pngcrush
Developer(s) | Glenn Randers-Pehrson |
---|---|
Stable release | 1.7.4
/ October 24, 2009 |
Repository | |
Written in | C |
Operating system | Cross-platform |
Type | Image optimizer |
License | OSI Approved License |
Website | pmt.sf.net/pngcrush/ |
pngcrush is a free, open source command-line utility that reduces the size of PNG files losslessly—that is, the resulting "crushed" 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 methods. However, pngcrush can also be used for various manipulations of PNG images, such as changing the bit depth.
pngcrush offers an optional "-brute" argument which attempts to brute force the crush when set: rather than use one of a few common methods to crush the file, it will try all of them.
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 can be told to generate a "crushed" file from an unoptimized one by using the following format on the command line:
pngcrush imageIn.png imageOut.png
Reducing filesize by removing color-correction data
One of pngcrush's features is the ability to 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, removing it can produce file sizes that are up to 40% smaller than the original. pngcrush, when told, will also losslessly reduce the bit-depth of images or apply a color palette when possible if doing so results in a smaller file size.
All ancillary chunks and text chunks can be removed using the following options:
pngcrush -rem gAMA -rem alla -rem text InputFile.png OutputFile.png
Image manipulation
pngcrush can be used to change the color encoding of an image. For example, if an image contains 10 colors but has a color palette of 256 entries (8-bit), pngcrush can be used to reduce the color 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 color type of the image. For a true-color image, changing the color type from 2 to 0 (-c 0
) converts it to greyscale. Greyscale images are generally smaller than truecolor images because, in addition to the optional alpha channel, only one 8-bit channel is used per pixel rather than three. Greyscale images are also generally smaller than paletted images because they do not need to define a color palette. For a truecolor-alpha image, changing the color 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, a 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
Similar PNG compression programs include:
References
- Steve Souders, Even Faster Web Sites: Essential Knowledge for Frontend Engineers, O'Reilly Media, 2009, ISBN 0596522304, p. 142
- Khalid Sayood, Lossless compression handbook, Academic Press, 2003, ISBN 0126208611, pp. 386-388
External links
- pngcrush home page
- pngutils for the Win32 console
- Quickly compress PNG images - Adds the "crush" option to the context menu of Windows Explorer.