Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save igor-kamil/44511df5f033eae2f749eeb9256792b4 to your computer and use it in GitHub Desktop.
Save igor-kamil/44511df5f033eae2f749eeb9256792b4 to your computer and use it in GitHub Desktop.
Recursively optimize all PNG and JPG files wherever they are from the script position and inner ( based on OPTING, PNGCRUSH, ADVANCECOMP and JPEGOPTIM )
#!/bin/bash
#resize (only larger) first:
find . -maxdepth 5 \( -iname \*.png -o -iname \*.jpg -o -iname \*.jpeg -o -iname \*.bmp \) -exec convert -resize 1500\> -verbose "{}" "{}" \;
#optimize
find . -type f -name "*.png" -o -name "*.PNG" | xargs optipng -nb -nc
find . -type f -name "*.png" -o -name "*.PNG" | xargs advpng -z4
find . -type f -name "*.png" -o -name "*.PNG" | xargs pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time -ow
find . -iname "*.png" -exec pngquant --force --verbose \{} --output \{} \;
find . -type f -iname '*.jpg' -exec jpegoptim --max=85 --strip-all {} +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment