From cc9353cd6132e2460097b90f053592771e030a9d Mon Sep 17 00:00:00 2001 From: jim kolpack Date: Fri, 1 May 2026 21:44:01 -0400 Subject: [PATCH] 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. --- images_resize.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/images_resize.sh b/images_resize.sh index 0c7575d..d159c72 100755 --- a/images_resize.sh +++ b/images_resize.sh @@ -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)