LinuxCommandLibrary

pngquant

Compress PNG images lossily

TLDR

Compress a specific PNG as much as possible and write result to a new file

$ pngquant [path/to/file.png]
copy

Compress a specific PNG and override original
$ pngquant --ext .png --force [path/to/file.png]
copy

Try to compress a specific PNG with custom quality (skip if below the min value)
$ pngquant --quality [0-100] [path/to/file.png]
copy

Compress a specific PNG with the number of colors reduced to 64
$ pngquant [64] [path/to/file.png]
copy

Compress a specific PNG and skip if the file is larger than the original
$ pngquant --skip-if-larger [path/to/file.png]
copy

Compress a specific PNG and remove metadata
$ pngquant --strip [path/to/file.png]
copy

Compress a specific PNG and save it to the given path
$ pngquant [path/to/file.png] --output [path/to/file.png]
copy

Compress a specific PNG and show progress
$ pngquant --verbose [path/to/file.png]
copy

SYNOPSIS

pngquant [options] [--] [file ...]

PARAMETERS

--ext
    Suffix for quantized files. Use '.png' to overwrite.

--force
    Overwrite existing files.

--nofs
    Disable Floyd-Steinberg dithering.

--ordered
    Use ordered dithering (may be faster, lower quality).

--quality -
    Set min/max quality range (0-100). Images below the minimum quality will be skipped.

--speed <1-11>
    Set speed/quality trade-off (1=slowest, best quality, 11=fastest, lowest quality). Default: 3.

--verbose
    Print verbose information.

--version
    Print version number and exit.

--strip
    Strip ancillary chunks (metadata).

--posterize
    Reduce the number of bits per channel.

--floyd
    Enable Floyd-Steinberg dithering.

--gamma
    Assume the source image has this gamma.

--output
    Write image to the specified file.

DESCRIPTION

pngquant is a command-line utility and library for lossy compression of PNG images. It converts 24/32-bit PNGs to 8-bit (or smaller) paletted PNGs, significantly reducing file size while often preserving perceived image quality.

It uses a combination of adaptive color quantization, dithering, and transparency optimization to achieve the best possible compression without introducing noticeable artifacts. pngquant is widely used to optimize images for the web and mobile devices, where smaller file sizes translate to faster loading times and reduced bandwidth consumption.

The command is particularly effective for images with a large number of colors but smooth gradients. Unlike lossless PNG optimization tools, pngquant deliberately reduces the number of colors in the image, which is the key to its impressive file size reductions. It is therefore important to carefully adjust its settings to balance file size and image quality.

CAVEATS

Lossy compression means image quality *will* be reduced. Carefully choose the quality setting to find a balance between file size and acceptable quality.

EXIT STATUS

pngquant exits with status 0 if all files were successfully processed. It returns 98 if any file processing failed, and 99 if there was an internal error.

QUALITY PARAMETER

The --quality parameter is essential for controlling the trade-off between file size and image quality. A lower quality value results in smaller files but potentially more noticeable artifacts.

HISTORY

pngquant was initially developed by Kornel Lesinski. It gained popularity as a reliable and efficient solution for PNG compression, especially within web development communities. It continues to be actively developed and maintained with new features and optimizations being added regularly. Usage of pngquant rose in line with web use, where optimizing media is important to provide a good experience for the consumer.

SEE ALSO

optipng(1), pngcrush(1)

Copied to clipboard