Skip to content

Instantly share code, notes, and snippets.

@acrookston acrookston/pngbai
Last active Dec 24, 2015

Embed
What would you like to do?
#!/bin/sh
## Packages:
# brew install pngcrush optipng advancecomp
# brew install https://gist.github.com/acrookston/7726731/raw/3e3ce6c177a450c375e3622636f4d55bbe5289f6/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
You can’t perform that action at this time.