Thursday, December 8, 2011

Shrinking PNG images using pngcrush

pngcrush is a free, open source command-line utility for optimizing PNG image files. It reduces the size of the file losslessly – that is, the resulting "crushed" image will have the same quality as the source image… more on Wikipedia

Allow me to show you what pngcrush can and cannot do by illustrating it using Wikipe-tan, the moe anthropomorphism of Wikipedia (click on the images to see them at full size).

Here is the original Wikipe-tan image (well, actually a PNG rendering of the original SVG vector graphics):

Original Wikipe-tan
152,005 bytes

Applied to this particular image, pngcrush can generate a file that is 20 percent smaller – without any loss of image information.

Wikipe-tan after pngcrush
121,412 bytes

While pngcrush reduces the image size considerably, it cannot free you from optimizing the image, for example by deciding whether reducing the amount of data in a lossy manner is acceptable.

Wikipe-tan, 256 colors
42,658 bytes

For the last image it made no difference whether I use pngcrush or not, GIMP already created the optimally compressed version that is 72% smaller than the original. Whether the loss in quality is acceptable for this image or not depends on the background; on an unstructured background it may not be the best choice but if the background has some structure it works quite well. As always: It pays to know what you are doing ☺

As far as running pngcrush there is not much to say. Here is a normal run of the program:

pngcrush

And here is a run with the -brute option that tries each and any possible way of compressing.

pngcrush -brute

Note that while it sometimes yields better results, using -brute usually is just waste of time.

No comments:

Post a Comment