Compressing pngs
When you’ve got a designer that often makes awesome but heavy PNG designs (I’m talking about 400K-700K for background images!!) you really must get moving if you don’t want your app to take ages to load. I just found something that helps (of course, you still need to talk to her anyway) but doing this won’t harm:
Get the program pngcrush.
#For Linux
apt-get install pngcrush
#For Mac !Get first Macports*
sudo port install pngcrush
* MacPorts
As the name suggests it will crush your PNG images to a smaller size. It won’t do miracles but it will make your loads lighter. The query I found to get most satisfactory results is this one:
pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB -brute originalFile resizedFile
I did a script to make this automatically for all files, take it if you want:
./reduce.sh
#!/bin/bash
crushed="crushed_"
for file in *.png
do
dest="$(echo $crushed$file)"
pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB -brute $file $dest
echo -n "Crushing $src ... "
done
read -p "Files crushed\n Overwrite original files? (y/N) "
if [ "$REPLY" == "y" ]
then
for crushed in $(ls | grep crushed_)
do
original="$(echo $crushed | cut -c 9-)"
mv $crushed $original
done
fi
Execute this script (remember to do chmod +x first) in your images folder. It will let you check the files before overwriting them. If you are happy with the results, type ‘y’ and the lighter PNG images will replace the old ones.
Tags: compress pngspngcrushreduce sizesmaller website images
2 Comments »






2 Comments on “Compressing pngs”
Follow comments feed
And if you need to get it done in seconds, with no installation, try http://developer.yahoo.com/yslow/smushit/
Thanks for the link! I tried it and a got similar ratio of compression, for a single file it looks more comfortable.