Pngcrush

From Wikipedia, the free encyclopedia

The correct title of this article is pngcrush. The initial letter is shown capitalized due to technical restrictions.
pngcrush
pngcrush screenshot
pngcrush 1.5.10
Developer: Glenn Randers-Pehrson
Latest release: 1.6.4 (source) / June 8, 2006
OS: Cross-platform
Use: Image optimizer
License: OSI Approved License
Website: pmt.sf.net/pngcrush/

pngcrush is an open source, free command line computer program that reduces the size of PNG files. The compression is lossless, meaning that the resulting image will have the same quality as the source image. The main purpose of pngcrush is to reduce the size of the PNG IDAT datastream by trying various compression levels. However, pngcrush can also be used for various manipulations of PNG images, such as changing the bit depth. Some operations can even increase the file size.

There is an optional "-brute" option, which performs a brute force crush when set: rather than use one of a few common methods to crush the file, it will try all of them.

Contents

[edit] Main operation

The main use of pngcrush is for reducing the size of the image data contained in the IDAT section. PNG uses DEFLATE compression which can vary in speed and compression ratio, from nearly no compression at all but at very high speed to the very good compression ratio, albeit at a lower speed. The PNG compressors built into many paint programs may not always apply the maximum amount of compression possible, and it is on images from these programs that pngcrush performs best.

pngcrush generates an "optimised" file from an unoptimised one using the following format on the command line:

pngcrush image1.png image2.png

pngcrush may not always generate the smallest PNG file possible. Because of different or more exhaustive search strategies being used, some other programs may give better results by several percent on certain files. OptiPNG, AdvanceCOMP and Ken Silverman's PNGOUT, for example, can sometimes outperform pngcrush in regards to PNG file sizes, although the time taken (and in some cases, the required manual labour on the user's behalf) to reach the result is usually increased.

[edit] Reducing filesize by removing color-correction data

pngcrush has one advantage over the other programs because it can remove all the color-correction data (gamma, white balance, ICC color profile, standard RGB color profile) from PNG files, using the following command line options:

pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB InputFile.png OutputFile.png

Since most graphics software embed the extra color-correction data which is normally not needed, this can produce file sizes that are up to 40 % smaller than the original. Greater reductions come from PNG images that have 256 colors or less (indexed color).

[edit] Image manipulation

pngcrush can be used to change the parameters of an image. For example, if an image contains 10 colours but has a colour palette of 256 entries (8-bit), pngcrush can be used to reduce the colour palette to a 4-bit one and truncate the palette to 10 entries:

pngcrush -bit_depth 4 -plte_len 10 image1.png image2.png

pngcrush can also change the colour type of the image. For a truecolour image, changing the colour type from 2 to 0 (-c 0) converts it to greyscale. For a truecolour-alpha image, changing the colour type from 6 to 2 removes the alpha channel.

[edit] Chunk and metadata manipulation

PNG images contain chunks with information about the image, such as its resolution (the pHYs chunk), the time it was last modified (the tIME chunk) and textual metadata (the tEXt chunk and its variants). With pngcrush the user can edit or remove those ancillary chunks:

pngcrush -res 96 -rem tIME -text b "Software" "pngcrush" image1.png image2.png

The above command sets the image resolution to 96 dpi, removes the timestamp and writes a textual metadata chunk describing pngcrush as the creation software of the image.

[edit] See also

Other PNG compression programs include:

[edit] External links

In other languages