pngcrush
Optimize PNG image file size
TLDR
Compress a PNG file
Compress all PNGs and output them to the specified directory
Compress PNG file with all 114 available algorithms and pick the best result
SYNOPSIS
pngcrush [OPTIONS] infile.png [outfile.png]
When outfile.png is omitted, infile.png is processed in-place (overwritten).
PARAMETERS
-reduce
Tries all possible filter and compression methods to find the smallest file size.
-brute
Similar to -reduce but attempts even more combinations, potentially yielding better compression at the cost of significantly longer processing time.
-m <method>
Specifies the compression method(s) to use. Common methods include 0 (deflate) or 1 (fixed Huffman).
-f <filter>
Selects the PNG filter type(s) to apply (0=None, 1=Sub, 2=Up, 3=Average, 4=Paeth, 5=Adaptive). Using adaptive filtering is often recommended.
-l <level>
Sets the zlib compression level, a value from 0 (no compression) to 9 (maximum compression). Default is usually 9.
-rem <chunk_name>
Removes specified ancillary chunks from the PNG file (e.g., tEXt, tIME, sRGB) to reduce file size or for privacy concerns. Use -rem all to remove all non-critical chunks.
-ow
Allows overwriting the original infile.png when an outfile.png is not provided. This is the default behavior if no output file is specified.
-v
Enables verbose output, displaying detailed progress and optimization results during processing.
DESCRIPTION
pngcrush is a command-line utility designed to optimize PNG image files by reducing their size without any loss of image quality. It achieves this lossless compression by exhaustively trying various filter methods, zlib compression levels, and other encoding strategies. pngcrush then selects the combination that results in the smallest possible file. It's particularly useful for images created with less optimal compression, enabling significant file size reductions often crucial for web performance. The tool supports all standard PNG features, including transparency and different color types. While it can be slower than some modern optimizers due to its brute-force approach, it is highly effective in finding the optimal compression for a given PNG image. Users can configure its behavior to focus on speed or maximum compression.
CAVEATS
pngcrush, especially with options like -brute or high iteration counts, can be very slow and resource-intensive, consuming significant CPU and memory. It may not always produce a smaller file if the original PNG is already highly optimized, and in rare cases, the output file size might even increase slightly.
LOSSLESS OPTIMIZATION
A key characteristic of pngcrush is that it performs lossless optimization. This means the image quality remains identical to the original; only the file size is reduced through more efficient encoding and compression without discarding any pixel data.
CHUNK MANAGEMENT
pngcrush provides powerful features for managing PNG chunks. Users can explicitly remove or keep various ancillary chunks (e.g., metadata like creation time, software information, or gamma correction data). This allows for further file size reduction and can be important for privacy or specific rendering requirements.
HISTORY
pngcrush was created by Glenn Randers-Pehrson and first released in the late 1990s. It has been a foundational tool for lossless PNG optimization, predating many other popular optimizers. Its development has focused on exhaustive search algorithms to achieve maximum compression, making it a reliable choice for achieving the smallest possible PNG file sizes. Despite its age, it remains actively maintained and widely used for its robust optimization capabilities.