Efficient compression of PNG images on Linux reduces bandwidth usage, shortens upload times, and saves storage while preserving transparency and sharp edges. Smaller image assets improve page load performance for websites, documentation, and web applications without forcing a move to lossy formats such as JPEG.
The PNG format uses lossless DEFLATE compression and stores full-color images with an optional alpha channel. The pngquant utility reduces file size by converting 24/32‑bit RGBA images to 8‑bit palette PNGs using perceptual quantization, typically cutting file size by 50–70% while keeping most images visually indistinguishable from the original, especially icons, UI elements, and diagrams.
Because the quantization step is lossy, backups or version control are important before replacing originals in production assets. By default, pngquant writes a new file with the ‑fs8 suffix instead of modifying the source image, which simplifies side‑by‑side comparison. Commands rely on a working terminal environment on Linux and expect basic familiarity with navigating directories and inspecting files.
$ sudo apt update && sudo apt install --assume-yes pngquant
On Fedora, CentOS Stream, and Red Hat Enterprise Linux, a similar result is obtained with sudo dnf install --assumeyes pngquant; on openSUSE, use sudo zypper install --no-confirm pngquant.
$ cd /path/to/images
$ ls -lh sample.png -rw-r--r-- 1 root root 23M Jan 14 00:27 sample.png
Checking the original size provides a baseline for evaluating the compression gain.
$ pngquant --verbose sample.png sample.png: conserving memory read 23169KB file too many colors! Scaling colors to improve clustering... 1 made histogram...496244 colors found selecting colors...14% selecting colors...100% moving colormap towards local minimum eliminated opaque tRNS-chunk entries...0 entries transparent mapped image to new colors...MSE=14.544 (Q=56) writing 256-color image as sample-fs8.png Quantized 1 image.
By default, pngquant writes a new file named with the ‑fs8 suffix so the original image remains unchanged.
$ ls -lh sample*.png -rw-r--r-- 1 root root 2.4M Jan 14 00:28 sample-fs8.png -rw-r--r-- 1 root root 23M Jan 14 00:27 sample.png
The size reduction indicates how effective the quantization was for the specific image.
$ pngquant --quality 40-80 --speed 1 --output sample-quality.png sample.png
Lower --quality values and slower --speed settings typically improve visual fidelity at the cost of processing time.
$ pngquant --help
pngquant, 2.18.0 (January 2023), by Kornel Lesinski, Greg Roelofs.
Compiled with no support for color profiles. Using libpng 1.6.43.
usage: pngquant [options] [ncolors] -- pngfile [pngfile ...]
pngquant [options] [ncolors] - >stdout <stdin
options:
--force overwrite existing output files (synonym: -f)
--skip-if-larger only save converted files if they're smaller than original
--output file destination file path to use instead of --ext (synonym: -o)
--ext new.png set custom suffix/extension for output filenames
--quality min-max don't save below min, use fewer colors below max (0-100)
--speed N speed/quality trade-off. 1=slow, 4=default, 11=fast & rough
--nofs disable Floyd-Steinberg dithering
--posterize N output lower-precision color (e.g. for ARGB4444 output)
--strip remove optional metadata (default on Mac)
--verbose print status messages (synonym: -v)
##### snipped #####
Options such as --skip-if-larger and --ext are useful when integrating pngquant into build pipelines or scripts.
Replacing original assets without visually checking the compressed output can introduce visible banding or color shifts in gradients, logos, or brand colors.