optipng
Optimize PNG image file size
TLDR
Compress a PNG with default settings
Compress a PNG with the best compression
Compress a PNG with the fastest compression
Compress a PNG and add interlacing
Compress a PNG and preserve all metadata (including file timestamps)
Compress a PNG and remove all metadata
SYNOPSIS
optipng [options] file1.png [file2.png ...]
PARAMETERS
-?, -h, --help
Show this help screen.
-o
Set optimization level (0-7, default is 2). Higher levels take longer but may result in smaller files.
-v, --verbose
Enable verbose mode.
-quiet
Enable quiet mode. Suppress informative messages.
-zc
zlib compression level (1-9, default is 9).
-zm
zlib memory level (1-9, default is 8).
-zs
zlib compression strategy (0-3, default is 0).
-f
PNG filter type (0-5, default is 5).
-fix
Enable error recovery.
-force
Enforce overwriting of output files.
-keep
Keep original files.
-out
Specify the output file name.
--
Treat subsequent arguments as file names.
DESCRIPTION
OptiPNG is a command-line PNG optimizer that attempts to reduce the file size of PNG images without losing any image information. It achieves this through a variety of techniques, including recompression using different compression levels and algorithms, removing unnecessary metadata, and optimizing the image's color palette. OptiPNG is particularly useful for web developers and anyone who wants to reduce the bandwidth consumption and loading times of their PNG images.
It can significantly reduce PNG file sizes, often by 10-50%, while preserving the original image quality. The tool supports a wide range of PNG formats and features, including interlacing, alpha channels, and various color types. It is a lossless process, meaning the image quality remains the same after optimization.
CAVEATS
OptiPNG modifies the input PNG files in place unless specified otherwise with the `-out` option. Running it on important or original files without a backup strategy is risky. Optimization levels higher than the default may not always provide significantly better compression at the cost of substantially longer processing times.
EXIT STATUS
OptiPNG returns 0 on success and a non-zero value on failure. Errors can include file not found, invalid PNG format, or insufficient memory.
EXAMPLES
Optimize a single PNG file with the default optimization level: `optipng image.png`. Optimize multiple PNG files with a higher optimization level: `optipng -o3 image1.png image2.png`. Optimize a PNG file and save the output to a different file: `optipng -o5 -out optimized.png image.png`.
HISTORY
OptiPNG was initially developed by Cosmin Truta. Its development has been driven by the need for efficient and lossless PNG compression, especially for web applications. The command has become a standard tool in web development and image processing workflows.
SEE ALSO
pngcrush(1), advpng(1)