Saturday, May 1, 2010

Optimizing PNG with optipng and pngcrush

There several tools to perform lossless optimization of images in PNG format.
My favourite GNU/Linux distro repositories contain two ones: optipng and pngcrush.

Pngcrush is invoked as follows:

$> pngcrush -e .opt.png -brute *.png

The command tries to reduce size of all PNG files from current directory (*.png) using brute-force search (-brute). Of course, you may omit the -brute key and use default heuristics (which is much faster and produce comparable compression). Resulting files will have .opt.png suffix (-e .opt.png), i.e. vpn-nm-7.png becomes vpn-nm-7.opt.png.

In order to get more information on pngcrush command line keys type:

$> pngcrush -h | less

Another program, optipng, is a bit more friendly, for my taste.
Its syntax is quite similar:

$> optipng -keep -o7 *.png

The command optimizes all PNG images from current directory (*.png) using exhastive search (-o7) and keeps backups (-keep).

As usual, in order to get more information on optipng type:

$> man optipng 

Finally, I have written down compression ratios of pngcrush and optipng on my eight small test PNG files obtained from KSnapshot.

pngcrush - 265594/292891 bytes - 90.7%
optipng  - 262938/292891 bytes - 89.8%

No comments:

Post a Comment