fff8e346ad
- Add optional directory argument to images_resize_recursive.sh, zip_images_resize_recursive.sh, and new rar2zip_recursive.sh - Remove hardcoded-path wrappers rar2zip_images.sh and rar2zip_incomplete.sh - Fix zip_images_resize.sh: move SCRIPT_DIR to top, change exit 1 to continue on bad output file so remaining files still process - Use MAX_PIXELS variable in images_resize.sh resize argument - Fix zip_images_recursive.sh: replace case-sensitive 7z globs with find -iregex piped via xargs
32 lines
1.1 KiB
Bash
Executable File
32 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# images_resize Resizing large JPGs in current directory
|
|
# Based on: https://shkspr.mobi/blog/2016/12/converting-rar-to-zip-in-linux/
|
|
#
|
|
# Usage: xxx.sh
|
|
|
|
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
|
|
read -r IMG_W IMG_H < <(~/Applications/magick identify -format "%w %h" "$f" 2>/dev/null)
|
|
if [[ -n "$IMG_W" && -n "$IMG_H" && $((IMG_W * IMG_H)) -le "$MAX_PIXELS" ]]; then
|
|
echo "Skipping $f: ${IMG_W}x${IMG_H} 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)
|
|
|
|
~/Applications/magick "$f" -resize "${MAX_PIXELS}@@\>" -sampling-factor 4:2:0 -strip -quality 85% "$f"
|
|
|
|
# Get file size after resizing
|
|
SIZE_AFTER=$(stat -f%z "$f" 2>/dev/null || stat -c%s "$f" 2>/dev/null)
|
|
|
|
# Display before/after sizes
|
|
echo "Resized $f: $(numfmt --to=iec-i --suffix=B $SIZE_BEFORE) -> $(numfmt --to=iec-i --suffix=B $SIZE_AFTER)"
|
|
done
|