Thursday, February 21, 2013

Optimize PNG files with Pngcrush

One of the problems I face often when working with png files on websites is their size. Gimp, Inkscape, Krita, MyPaint, Blender and many other applications are capable of exporting to PNG but the file is usually quite big.

To solve this problem we can use a simple command line program called Pngcrush.

Installation in debian based systems are as simples as running,as a super user or using sudo, the following command on console:

apt-get install pngcrush

To optimize an PNG image file is as simples as

pngcrush -brute -e "Opt.png" filename.png

-brute - Use force brute. It will be time consuming as it will try 114 different filter/compression methods. The image sice reduction factor is significant using thins option.

-e "ext" - Specifi an extension for all output files. In the above example the new file is going to be called filenameOpt.png. This way you are not going to overwrite the original image.

To optimize all files in the a directory you can use:

pngcrush -brute -d "/home/user/path/to/dir/"  *.png