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]
optipng [options]
PARAMETERS
-o
Set optimization level (0-7). Higher levels perform more trials for better compression, but take longer.
-zc
Zlib compression level (1-9).
-zm
Zlib memory level (1-9).
-zs
Zlib compression strategy (0-3).
-f
PNG filter strategies (e.g., 0-5, m, p, e, b, N). Combines multiple filter types.
-i
Number of iterations (1-100). Increases chances of finding optimal compression.
-nb
Do not reduce bit depth.
-nc
Do not reduce color type.
-np
Do not reduce palette.
-nx
Do not change interlacing.
-fix
Fix common PNG errors.
-keep
Keep original file attributes (timestamp, permissions).
-strip
Strip metadata chunks. Common filters: all
, iptexif
, text
, srgb
, iccp
.
-q
Quiet mode; suppress output.
-v
Verbose mode; display detailed information.
-h, --help
Display help message and exit.
-V, --version
Display version information and exit.
DESCRIPTION
OptiPNG is a powerful command-line utility designed for losslessly compressing PNG (Portable Network Graphics) image files to their smallest possible size. Unlike lossy compression methods, OptiPNG ensures that the visual quality of the image remains identical to the original, only focusing on reducing file size through more efficient data storage. It achieves this by intelligently trying various compression methods, filter types, and color depth reductions, and then selecting the combination that yields the smallest output. This makes it an invaluable tool for web developers, designers, and anyone looking to optimize images for faster loading times, reduced bandwidth consumption, and lower storage requirements without any loss of quality. OptiPNG can process individual files, multiple files, or even entire directories, making batch optimization straightforward. Its meticulous approach often results in significant file size reductions, especially for images not previously optimized.
CAVEATS
OptiPNG performs lossless compression; it will not achieve size reductions by degrading image quality. Results depend heavily on the original image's characteristics and prior optimization. Higher optimization levels (e.g., -o7
) can be CPU-intensive and time-consuming, especially for large images or batch processing. While highly effective, it might not yield significant reductions for images already well-optimized or those with limited compression potential.
OPTIMIZATION LEVELS (-O)
The -o
option controls the optimization aggression, from 0 to 7.
Level 0: No optimization, only writes a new file.
Level 1: Basic optimization, equivalent to -zc9 -zm8 -zs0 -f0
.
Level 2: Good optimization, equivalent to -zc9 -zm8 -zs0 -f5
.
Level 3-7: Progressively more aggressive, trying more filter combinations, strategies, and iterations, taking significantly more time but potentially yielding smaller files. -o7
is the most exhaustive.
COMMON USAGE EXAMPLE
To optimize all PNG files in the current directory with a good balance of speed and compression:optipng -o5 *.png
To optimize a single file and be very aggressive, displaying verbose output:optipng -o7 -v input.png -out optimized.png
HISTORY
OptiPNG was initially developed by Cosmin Truta, with its first public release around 2001. The project's primary goal was to create a PNG optimizer that could achieve better compression ratios than existing tools, leveraging advanced algorithms and exhaustive search strategies. It quickly gained traction, particularly among web developers, due to its ability to significantly reduce file sizes without any loss of visual fidelity. Over the years, it has seen continuous development, incorporating new PNG specifications and compression techniques, solidifying its position as a go-to tool for lossless PNG optimization on Linux and other platforms.