Created
October 18, 2012 01:36
-
-
Save tony-landis/3909387 to your computer and use it in GitHub Desktop.
Recursively Optimize JPGs and PNGs using PNGCRUSH and JPEGTRAN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# script for optimizing images in a directory (recursive) | |
# pngcrush & jpegtran settings from: | |
# http://developer.yahoo.com/performance/rules.html#opt_images | |
# pngcrush | |
for png in `find . | grep .png`; do | |
echo "crushing $png ..." | |
pngcrush -rem alla -reduce -brute "$png" temp.png | |
# preserve original on error | |
if [ $? = 0 ]; then | |
mv -f temp.png $png | |
else | |
rm temp.png | |
fi | |
done | |
# jpegtran | |
for jpg in `find . | grep .jpg`; do | |
echo "crushing $jpg ..." | |
jpegtran -copy none -optimize -perfect "$jpg" > temp.jpg | |
# preserve original on error | |
if [ $? = 0 ]; then | |
mv -f temp.jpg $jpg | |
else | |
rm temp.jpg | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment