Skip images already within pixel limit
Check pixel count before processing and skip files that are already at or below 8MP, avoiding unnecessary re-compression.
This commit is contained in:
@@ -7,8 +7,17 @@
|
|||||||
|
|
||||||
echo "Resizing large JPGs in $(pwd)"
|
echo "Resizing large JPGs in $(pwd)"
|
||||||
|
|
||||||
|
MAX_PIXELS=8000000
|
||||||
|
|
||||||
find . -regextype posix-egrep -regex ".*\.(jpg|JPG|JPEG|jpeg)$" -print0 | while IFS= read -r -d '' f
|
find . -regextype posix-egrep -regex ".*\.(jpg|JPG|JPEG|jpeg)$" -print0 | while IFS= read -r -d '' f
|
||||||
do
|
do
|
||||||
|
# Check pixel count before processing
|
||||||
|
PIXELS=$(~/Applications/magick identify -format "%[fx:w*h]" "$f" 2>/dev/null)
|
||||||
|
if [[ -n "$PIXELS" && "$PIXELS" -le "$MAX_PIXELS" ]]; then
|
||||||
|
echo "Skipping $f: ${PIXELS}px already within limit"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
# Get file size before resizing
|
# Get file size before resizing
|
||||||
SIZE_BEFORE=$(stat -f%z "$f" 2>/dev/null || stat -c%s "$f" 2>/dev/null)
|
SIZE_BEFORE=$(stat -f%z "$f" 2>/dev/null || stat -c%s "$f" 2>/dev/null)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user