Created
April 12, 2013 21:23
-
-
Save kpdecker/5375241 to your computer and use it in GitHub Desktop.
Prototype png color reduction script/linter
This file contains hidden or 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 | |
QUALITY=95 | |
DEPTHS="256 128 64 32 8 4 2" | |
totalSaved=0 | |
for name in `find "$1" -name "*.png" -not -name "*-fs8.png"`; do | |
output= | |
newName=${name%.png}-fs8.png | |
originalSize=`stat -f %z "$name"` | |
colors=`identify -verbose "$name" | grep Colors: | awk '{ print $2 }'` | |
for depth in $DEPTHS; do | |
if [ "$colors" != "" ]; then | |
if [ "$depth" -ge "$colors" ]; then | |
continue; | |
fi | |
fi | |
log=`pngquant -fv --speed 1 --quality $QUALITY-100 $depth -- "$name" 2>&1` | |
if [ $? -eq 0 ]; then | |
pngout $newName > /dev/null | |
newSize=`stat -f %z "$newName"` | |
deltaCheck=$(( originalSize - newSize )) | |
if [ $deltaCheck -gt 0 ]; then | |
#echo "$log" | |
mse=`echo "$log" | grep MSE | sed 's/.*\(MSE=.*\)/\1/'` | |
bytes=$deltaCheck | |
percent=$(( 100-(100*$newSize / $originalSize) )) | |
output="$output\n\t-$bytes bytes Colors: $depth $mse Size: $newSize $percent% smaller" | |
#compare -verbose -metric rmse $name $newName $name-compare-fs8.png | |
else | |
rm $newName | |
fi | |
fi | |
done | |
if [ "$output" != "" ]; then | |
totalSaved=$(( totalSaved + bytes )) | |
echo "$name size: $originalSize colors: $colors $output" | |
fi | |
done | |
echo "Possible savings: $totalSaved bytes" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment