Pngcrush

From Free net encyclopedia

Template:Lowercase Template:Infobox Software 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

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 often do not apply the best compression, and it is on images output from such programs that pngcrush best performs its role.

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

pngcrush image1.png image2.png

It should be noted that pngcrush seldom generates the smallest PNG possible. Many other programs can reach better results by several percent. OptiPNG, AdvanceCOMP and Ken Silverman's PNGOUT, for example, consistently better 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 increased.

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 anywhere from 1 % to 40 % smaller than the orignal. Greater reductions come from PNG images that have 256 colors or less (indexed color).

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.

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.

See also

Other PNG compression programs include:

External links