Pngcrush
Encyclopedia
pngcrush is a free
, 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 datastream by trying various combinations of compression methods and delta filters. However, pngcrush 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 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 5 possible filter types which can be specified separately on each scan line. In addition, there are several possible strategies of searching LZ77 matches. Thus, there is almost infinite number of different combinations on how the image can be compressed. Which combination gives the best compression depends on the image properties.
pngcrush compresses the image with multiple different combinations and then stores the smallest of the resulting files. Since it is not possible to go through all the combinations, pngcrush uses some heuristics to choose the methods to try.
In the simplest form, 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
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 more than 100 different crushing methods.
, 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 alla -rem text InputFile.png OutputFile.png
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 (
, 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.
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.
Similar JPG software:
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...
, open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...
command-line
Command-line interface
A command-line interface is a mechanism for interacting with a computer operating system or software by typing commands to perform specific tasks...
utility for optimizing PNG image files. It reduces the size of the file losslessly
Lossless data compression
Lossless data compression is a class of data compression algorithms that allows the exact original data to be reconstructed from the compressed data. The term lossless is in contrast to lossy data compression, which only allows an approximation of the original data to be reconstructed, in exchange...
— 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 combinations of compression methods and delta filters. However, pngcrush can also be used for various manipulations of PNG images, such as changing the bit depth
Color depth
In computer graphics, color depth or bit depth is the number of bits used to represent the color of a single pixel in a bitmapped image or video frame buffer. This concept is also known as bits per pixel , particularly when specified along with the number of bits used...
, removing unwanted ancillary chunks, or adding certain chunks including gAMA, tRNS, iCCP, and textual chunks.
Main operation
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
Huffman coding
In computer science and information theory, Huffman coding is an entropy encoding algorithm used for lossless data compression. The term refers to the use of a variable-length code table for encoding a source symbol where the variable-length code table has been derived in a particular way based on...
. This combination is referred to as DEFLATE compression. Before compressing, non-destructive delta filters are applied on the pixel data.
There are 5 possible filter types which can be specified separately on each scan line. In addition, there are several possible strategies of searching LZ77 matches. Thus, there is almost infinite number of different combinations on how the image can be compressed. Which combination gives the best compression depends on the image properties.
pngcrush compresses the image with multiple different combinations and then stores the smallest of the resulting files. Since it is not possible to go through all the combinations, pngcrush uses some heuristics to choose the methods to try.
In the simplest form, 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
By default, pngcrush uses just a few common methods to crush the file. The optional "-brute" argument can be used for brute force
Brute-force search
In computer science, brute-force search or exhaustive search, also known as generate and test, is a trivial but very general problem-solving technique that consists of systematically enumerating all possible candidates for the solution and checking whether each candidate satisfies the problem's...
crushing, which will try more than 100 different crushing methods.
Reducing filesize by removing color-correction data
One of pngcrush's features is the ability to remove all the color-correction data (gammaGamma correction
Gamma correction, gamma nonlinearity, gamma encoding, or often simply gamma, is the name of a nonlinear operation used to code and decode luminance or tristimulus values in video or still image systems...
, 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
Indexed color
In computing, indexed color is a technique to manage digital images' colors in a limited fashion, in order to save computer memory and file storage, while speeding up display refresh and file transfers...
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 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 channelAlpha compositing
In computer graphics, alpha compositing is the process of combining an image with a background to create the appearance of partial or full transparency. It is often useful to render image elements in separate passes, and then combine the resulting multiple 2D images into a single, final image in a...
, 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
Palette (computing)
In computer graphics, a palette is either a given, finite set of colors for the management of digital images , or a small on-screen graphical element for choosing from a limited set of choices, not necessarily colors .Depending on the context In computer graphics, a palette is either a given,...
. 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
Dots per inch
Dots per inch is a measure of spatial printing or video dot density, in particular the number of individual dots that can be placed in a line within the span of 1 inch . The DPI value tends to correlate with image resolution, but is related only indirectly.- DPI measurement in monitor...
, 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:- PNGOUTPNGOUTPNGOUT is a freeware command line optimizer for PNG images written by Ken Silverman. The compression is lossless, meaning that the resulting image will have exactly the same appearance as the source image...
- AdvanceCOMPAdvanceCOMPAdvanceCOMP is a set of cross-platform command line data compression tools. The utilities allow modifying an already-compressed file, with the intent of reducing the file-size by optimising the compressed representation...
- Image-PngslimmerImage-PngslimmerIn computer programming, Image::Pngslimmer is a Perl module of functions to reduce the size of PNG computer graphics. The module offers several basic functions, including:...
Similar JPG software:
- jpgcrush
External links
- pngcrush home page
- pngutils for the Win32 console
- Quickly compress PNG images - Adds the "crush" option to the context menu of Windows ExplorerWindows ExplorerThis article is about the Windows file system browser. For the similarly named web browser, see Internet ExplorerWindows Explorer is a file manager application that is included with releases of the Microsoft Windows operating system from Windows 95 onwards. It provides a graphical user interface...
.