Created
October 21, 2011 19:21
-
-
Save tessro/1304688 to your computer and use it in GitHub Desktop.
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 | |
## Packages: | |
# brew install pngcrush | |
# brew install optipng | |
# brew install advancemame | |
# brew install https://raw.github.com/adamv/homebrew-alt/23f9084410476da1fcaf946f24f4dde47fe888ea/non-free/pngout.rb | |
function usage { | |
echo "Usage: $0 infile outfile" | |
exit 1 | |
} | |
if [ ! $# -eq 2 ]; then | |
usage | |
elif [ ! -f $1 ]; then | |
usage | |
fi | |
infile=$1 | |
outfile=$2 | |
insize=`stat -f %z $infile` | |
echo "Compressing $infile -> $outfile" | |
function progress { | |
local outsize=`stat -f %z $outfile` | |
local savings=`expr $insize - $outsize` | |
local pct=`expr 100 \* $savings / $insize` | |
echo "$insize -> $outsize ($pct%)" | |
} | |
if which -s pngcrush; then | |
# pngcrush sometimes emits libpng warnings | |
pngcrush -q -rem cHRM -rem gAMA -rem iCCP -rem sRGB -l9 -brute $infile $outfile 2>/dev/null | |
else | |
# make sure $outfile exists | |
cp $infile $outfile | |
fi | |
if which -s optipng; then | |
optipng -q -o7 $outfile | |
fi | |
if which -s advpng; then | |
advpng -q -z4 $outfile | |
fi | |
if which -s pngout; then | |
pngout -q -s0 -y $outfile | |
fi | |
progress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment