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:
2026-05-01 21:44:01 -04:00
parent 97ba5eac6a
commit cc9353cd61
+9
View File
@@ -7,8 +7,17 @@
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
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
SIZE_BEFORE=$(stat -f%z "$f" 2>/dev/null || stat -c%s "$f" 2>/dev/null)