pngquant — Compress PNG Images with Lossy Quantization
Lossy PNG compressor that converts 24/32-bit images to 8-bit palettes – often 60–70 % smaller with barely visible quality loss.
pngquant shrinks PNG files dramatically by reducing 24/32-bit images to an 8-bit palette with alpha transparency – often 60–70 % smaller with barely any visible difference. The quantization is lossy, though: by default it writes a new name-fs8.png file, but --ext .png --force overwrites the original in place, so keep a backup. Where genuine lossless output is required, reach for optipng instead.
Basic Usage
pngquant <image.png> — Quantize to 256 colors, output as
pngquant screenshot.pngpngquant <n> <image.png> — Quantize to a specific number of colors (2-256).
pngquant 128 screenshot.pngpngquant --output <output.png> <input.png> — Write to a specific output file.
pngquant --output optimized.png original.pngpngquant -o <output.png> <input.png> — Short form of --output.
pngquant -o small.png large.pngpngquant --ext .png --force <image.png> — Overwrite the original file in-place.
pngquant --ext .png --force screenshot.pngpngquant *.png — Batch quantize all PNGs (creates *-fs8.png files).
pngquant images/*.pngQuality Control
pngquant --quality=<min>-<max> <image.png> — Set quality range (0-100). Aborts with exit code 99 if min can't be achieved.
pngquant --quality=65-80 photo.pngpngquant --quality=80-100 <image.png> — High quality (subtle compression, smaller savings).
pngquant --quality=80-100 icon.pngpngquant --quality=45-65 <image.png> — Aggressive compression (larger savings, visible on close inspection).
pngquant --quality=45-65 background.pngpngquant --quality=0-100 <image.png> — Accept any quality (never aborts, maximum compression).
pngquant --quality=0-100 image.pngpngquant --skip-if-larger <image.png> — Don't write output if it would be larger than the original.
pngquant --skip-if-larger icon.pngColor & Dithering
pngquant 64 <image.png> — Reduce to 64 colors (good for simple graphics).
pngquant 64 icon.pngpngquant 16 <image.png> — Reduce to 16 colors (very small, best for icons/logos).
pngquant 16 logo.pngpngquant --nofs <image.png> — Disable Floyd-Steinberg dithering (sharper edges, potential banding).
pngquant --nofs icon.pngpngquant --floyd=<n> <image.png> — Set dithering level (0.0 = none, 1.0 = full, default: 1.0).
pngquant --floyd=0.5 photo.pngpngquant --posterize <bits> <image.png> — Reduce precision of color channels (useful for gradients).
pngquant --posterize 4 gradient.pngSpeed & Performance
pngquant --speed <n> <image.png> — Set speed/quality trade-off (1 = best quality, 11 = fastest).
pngquant --speed 1 photo.pngpngquant --speed 1 --quality=65-80 <image.png> — Slowest speed for best quality result.
pngquant --speed 1 --quality=65-80 hero-image.pngpngquant --speed 11 *.png — Fastest processing for batch operations.
pngquant --speed 11 thumbnails/*.pngOutput Options
pngquant --ext <suffix> <image.png> — Set output file suffix (default: -fs8.png).
pngquant --ext -small.png screenshot.pngpngquant --strip <image.png> — Strip all metadata from output.
pngquant --strip photo.pngpngquant - < <input.png> > <output.png> — Read from stdin, write to stdout (for piping).
cat input.png | pngquant - > output.pngpngquant --verbose <image.png> — Show detailed processing info (remapped colors, file sizes).
pngquant --verbose screenshot.pngCommon Patterns
pngquant --quality=65-80 --speed 1 --strip --ext .png --force *.png — Web optimization: in-place, stripped, quality-controlled.
pngquant --quality=65-80 --speed 1 --strip --ext .png --force assets/*.pngfind . -name '*.png' -exec pngquant --quality=65-80 --skip-if-larger --strip --ext .png --force {} \; — Recursively optimize all PNGs in-place (safe, skips if larger).
find public/ -name '*.png' -exec pngquant --quality=65-80 --skip-if-larger --strip --ext .png --force {} \;pngquant --quality=65-80 --strip photo.png && optipng -o2 photo-fs8.png — Pipeline: pngquant (lossy) then optipng (lossless) for maximum compression.
pngquant --quality=65-80 --strip photo.png && optipng -o2 photo-fs8.pngpngquant 256 --quality=80-100 --skip-if-larger --nofs logo.png — Optimize a logo/icon (no dithering for sharp edges, high quality).
pngquant 256 --quality=80-100 --skip-if-larger --nofs logo.pngfor f in *.png; do pngquant --quality=65-80 --strip -o "dist/$f" "$f"; done — Batch optimize into a separate directory.
mkdir -p dist && for f in src/*.png; do pngquant --quality=65-80 --strip -o "dist/$(basename $f)" "$f"; done Conclusion
pngquant is one of the most effective tools for lean web PNGs: with --quality 65-80, --speed and a sensible colour count you get large savings the eye won't notice. Keep in mind that the compression is lossy – once colours are quantized, they're gone for good. The default protects you by writing a fresh -fs8.png; the moment you combine --force with --ext .png (or --output), you overwrite the original irreversibly, so work from backups only. If the result falls below your quality minimum, pngquant aborts with exit code 99 and leaves the file untouched. For strictly lossless requirements, optipng is the right choice.
Further Reading
- pngquant – official website – documentation, options and downloads for the quantizer
- pngquant on GitHub – source code, issues and the underlying libimagequant library