Skip to content

Instantly share code, notes, and snippets.

@tessro
Created October 21, 2011 19:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tessro/1304688 to your computer and use it in GitHub Desktop.
Save tessro/1304688 to your computer and use it in GitHub Desktop.
#!/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