Skip to content

Instantly share code, notes, and snippets.

@elliotboney
Created April 22, 2022 13:26
Show Gist options
  • Save elliotboney/57c1b8c4d1c3794cce15d6f186d0e9ae to your computer and use it in GitHub Desktop.
Save elliotboney/57c1b8c4d1c3794cce15d6f186d0e9ae to your computer and use it in GitHub Desktop.
Resize ridiculous image files in a directory recursively
#!/usr/bin/env bash
trap 'exit 130' INT
TOTAL_FILES=`find $1 -type f -size +3M -iname "*.jpg" -printf '.' | wc -c`
INDEX=1
echo -e "${BWhite}Total files: ${BCyan}${TOTAL_FILES}${NC}"
for file in $(find $1 -type f -size +3M -iname "*.jpg"); do
echo -ne "${Gray}[${INDEX}/${TOTAL_FILES}]${White} $file --> ${BWhite}$(ls -lah $file | awk -F " " {'print $5'})${NC}"
# mogrify -resize '2560>' -quality 82 -define png:compression-level=9 -strip $file
mogrify -filter Triangle -define filter:support=2 -thumbnail '2560x>' \
-unsharp 0.25x0.25+8+0.065 -dither None -posterize 136 -quality 82 \
-define jpeg:fancy-upsampling=off -define png:compression-filter=5 \
-define png:compression-level=9 -define png:compression-strategy=1 \
-define png:exclude-chunk=all -interlace none -colorspace sRGB -strip $file
echo -e " => ${BGreen}$(ls -lah $file | awk -F " " {'print $5'})${NC}"
echo -e "${Gray}-------------------------------------------------------${NC}"
((INDEX=INDEX+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment