pngcrush | |
Developer: | Glenn Randers-Pehrson |
Latest Release Version: | 1.8.13[1] |
Latest Release Date: | [2] |
Operating System: | Cross-platform |
Programming Language: | C |
Genre: | Image optimizer |
License: | Similar to libpng License |
pngcrush is a free and 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.
The main purpose of pngcrush is to reduce the size of the PNG IDAT data stream by trying various combinations of compression methods and delta filters. It can also be used for various manipulations of PNG images, such as changing the bit depth, removing unwanted ancillary chunks, or adding certain chunks including gAMA, tRNS, iCCP, and textual chunks.
The main use of pngcrush is for reducing the size of the image data contained in the IDAT section.
The pixel data in a PNG file is compressed using LZ77 algorithm (which tries to find repeated byte sequences in the source data), and then further compressed with Huffman algorithm. This combination is referred to as deflate compression. Before compressing, non-destructive delta filters are applied on the pixel data.
There are five possible filter types that can be specified separately on each scan line and several possible strategies for searching LZ77 matches. Thus, there are a very large number of different combinations for how the image can be compressed. Which combination gives the best compression will depend on the individual image's properties.[3]
pngcrush compresses the image with multiple different combinations and then stores the smallest of the resulting files.[4] Since it is not possible to go through all the combinations, pngcrush uses heuristics to choose the methods to try.
By default, pngcrush uses just a few common methods to crush the file. The optional "-brute" argument can be used for brute force crushing, which will try 176 different crushing methods on version 1.8.12 and later or 148 crushing methods on versions 1.7.45 through 1.8.11.
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.[5]
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.
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 can also change the color type of the image. For a true-color image, changing the color type from 2 to 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.
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.