Skip to content

Instantly share code, notes, and snippets.

@paazmaya
Last active October 12, 2017 17:30
Show Gist options
  • Save paazmaya/d0d874df3c8aa9bf41e6a69c43e6984c to your computer and use it in GitHub Desktop.
Save paazmaya/d0d874df3c8aa9bf41e6a69c43e6984c to your computer and use it in GitHub Desktop.
Find image files and optimise them with different command line tools
#!/bin/bash
# Find all JPEG files and do stuff with https://github.com/google/guetzli
find . -maxdepth 4 -type f -iname '*.jpg' \
-exec sh -c '(guetzli "{}" "{}.jpg")' ';'
#!/bin/bash
# Find all JPEG files and do stuff with http://jpegclub.org/jpegtran/
find . -maxdepth 4 -type f -iname '*.jpg' \
-exec sh -c '(jpegtran -copy all -optimize -outfile "{}.jpg" "{}")' ';'
#!/bin/bash
# Find all PNG files and do stuff with https://github.com/pornel/pngquant/
find . -maxdepth 4 -type f -iname '*.png' \
-exec sh -c '(pngquant --skip-if-larger "{}")' ';'
#!/bin/bash
# Find the files just created and drop the extra suffix
find . -maxdepth 4 -type f -iname '*.jpg.jpg' \
-exec sh -c '(hoplaa={}; mv -f "{}" "${hoplaa%.jpg}")' ';'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment