Skip to content

Instantly share code, notes, and snippets.

@ZeppLu
Last active March 10, 2020 07:06
Show Gist options
  • Save ZeppLu/3eb7fa51a0281fb75fa022866d587893 to your computer and use it in GitHub Desktop.
Save ZeppLu/3eb7fa51a0281fb75fa022866d587893 to your computer and use it in GitHub Desktop.
Recursively compress JPEG/PNG, requires mozjpeg & imagemagick
export IFS="
"
# You may want to add patterns like "*.bmp", "*.tiff", etc
for i in $(find . \( -iname "*.jpg" \
-o -iname "*.jpeg" \
-o -iname "*.png" \)); do
echo "Compressing $i"
convert "$i" pnm:- | cjpeg > "$i.comp"
mv "$i" "$i.trash"
mv "$i.comp" "$i"
done
# To remove trash:
#find . -name "*.trash" -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment