pngcrush – Image Optimizer for PNG Graphics

pngcrush is a command line image optimizer for PNG graphics files. It optimizes a PNG graphics file by reducing the size of the file’s IDAT chunk. Pngcrush is not installed by default in Linux, but it is available in the repositories of most Linux distributions. In Ubuntu Linux, you can install pngcrush by running the following command :

$ sudo apt-get install pngcrush

pngcrush usage

Pngcrush has reasonable defaults so  running the command with no options may produce smaller files. Here is how I use it to optimize and reduce size of PNG files -

$ pngcrush -brute -e ".crush.png" filename.png

-brute – Use brute force, try 114 different filter/compression methods. This option is very time consuming but I was able to reduce the size of PNG images by significant factor using this option.

-e "ext" – Specify a new extension for all output files. In the above example, the output of the command will be a file named filename.crush.png . You can use any extension you want. This option ensures that the original file is not overwritten.

More examples

$ pngcrush -brute -d "/home/laf/images/pngcrush/"  *.png

All the files in the current directory are optimized and saved in the directory denoted by the -d option.

-d "dir" -  Pngcrush will save all the optimized images to the directory location denoted by dir. The output files will have the same name as the original files unless the -e option is used.

$ pngcrush -brute -c 0 -e ".crush.png" *.png

The above command optimizes and converts all images to grayscale without alpha channel (1,2,4,8,16).

-c type -  Set  the output image color type to type. This option can take values of 0,2,4, or 6 where -

0 – grayscale without alpha channel (1,2,4,8,16)
2 – true color without alpha channel (8,16)
3 – indexed color (1,2,4,8)
4 – grayscale with alpha channel (8,16)
6 – true color with alpha channel (8,16)

I was able to significantly reduce the size of images using pngcrush and optimize them for the web. optipng is another command line tool which can be used to optimize PNG images.

Please visit basic linux commands page to know how to use different Linux commands.

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Related posts: