LinuxCommandLibrary

zopflipng

Optimize PNG images for size

TLDR

Optimize a PNG

$ zopflipng [input.png] [output.png]
copy

Optimize several PNGs and save with given prefix
$ zopflipng --prefix=[prefix] [image1.png image2.png image3.png ...]
copy

SYNOPSIS

zopflipng [options] input.png [output.png]

PARAMETERS

input.png
    The PNG file to be optimized.

output.png (optional)
    The name of the optimized PNG file. If omitted, the original filename is used with '_opt.png' appended.

-m
    --iterations=N: Maximum amount of times to rerun Zopfli. More gives better results but longer running time. Default: 15.

-y
    --always-yes: Say yes to all questions (e.g. overwrite existing files).

-q
    --quiet: Do not print anything to stdout.

--lossy_transparent
    Allow converting fully transparent colors to grayscale. Can greatly lower size.

--lossy_8bit
    Convert image to 8-bit color. May greatly lower size.

--filters=01234mepb
    PNG filter strategy (0-4, m=min, e=entropy, p=predefined, b=brute force). Default: me.

DESCRIPTION

zopflipng is a command-line tool that optimizes PNG (Portable Network Graphics) images using the Zopfli compression algorithm. Zopfli is a lossless compression algorithm developed by Google that produces smaller PNG files compared to other common PNG optimizers like optipng or pngcrush.

While Zopfli offers better compression ratios, it achieves this at the cost of significantly longer processing times. This makes zopflipng particularly useful for compressing images where file size is paramount, such as web graphics, especially when serving from a CDN, or archiving, and the time is less critical. It's not suitable for real-time applications. The tool supports various optimization options, including different compression levels, filter strategies, and color type reduction, allowing fine-tuning of the compression process.

The optimized image is created with the original filename with the suffix _opt.png. Overwriting can be achieved with additional parameters. The utility aims to reduce the size of PNG images without affecting their visual quality.

CAVEATS

The primary limitation of zopflipng is its significantly longer processing time compared to other PNG optimization tools. This makes it less suitable for applications where speed is crucial.

MEMORY USAGE

zopflipng can use a significant amount of memory, especially when processing large images or using higher compression levels. Ensure that your system has sufficient RAM available.

BEST PRACTICES

For best results, experiment with different compression levels and filter strategies to find the optimal balance between file size reduction and processing time. Consider using zopflipng in conjunction with other PNG optimization tools for a multi-stage optimization process.

HISTORY

zopflipng was created by Google as a demonstration and practical application of the Zopfli compression algorithm. The goal was to provide a tool that could achieve the highest possible PNG compression, even at the expense of processing time. It has been widely adopted by web developers and image archivists seeking to minimize the file size of their PNG images.

SEE ALSO

optipng(1), pngcrush(1)

Copied to clipboard