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 -fs8.png.

pngquant screenshot.png

pngquant <n> <image.png> — Quantize to a specific number of colors (2-256).

pngquant 128 screenshot.png

pngquant --output <output.png> <input.png> — Write to a specific output file.

pngquant --output optimized.png original.png

pngquant -o <output.png> <input.png> — Short form of --output.

pngquant -o small.png large.png

pngquant --ext .png --force <image.png> — Overwrite the original file in-place.

pngquant --ext .png --force screenshot.png

pngquant *.png — Batch quantize all PNGs (creates *-fs8.png files).

pngquant images/*.png

Quality 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.png

pngquant --quality=80-100 <image.png> — High quality (subtle compression, smaller savings).

pngquant --quality=80-100 icon.png

pngquant --quality=45-65 <image.png> — Aggressive compression (larger savings, visible on close inspection).

pngquant --quality=45-65 background.png

pngquant --quality=0-100 <image.png> — Accept any quality (never aborts, maximum compression).

pngquant --quality=0-100 image.png

pngquant --skip-if-larger <image.png> — Don't write output if it would be larger than the original.

pngquant --skip-if-larger icon.png

Color & Dithering

pngquant 64 <image.png> — Reduce to 64 colors (good for simple graphics).

pngquant 64 icon.png

pngquant 16 <image.png> — Reduce to 16 colors (very small, best for icons/logos).

pngquant 16 logo.png

pngquant --nofs <image.png> — Disable Floyd-Steinberg dithering (sharper edges, potential banding).

pngquant --nofs icon.png

pngquant --floyd=<n> <image.png> — Set dithering level (0.0 = none, 1.0 = full, default: 1.0).

pngquant --floyd=0.5 photo.png

pngquant --posterize <bits> <image.png> — Reduce precision of color channels (useful for gradients).

pngquant --posterize 4 gradient.png

Speed & Performance

pngquant --speed <n> <image.png> — Set speed/quality trade-off (1 = best quality, 11 = fastest).

pngquant --speed 1 photo.png

pngquant --speed 1 --quality=65-80 <image.png> — Slowest speed for best quality result.

pngquant --speed 1 --quality=65-80 hero-image.png

pngquant --speed 11 *.png — Fastest processing for batch operations.

pngquant --speed 11 thumbnails/*.png

Output Options

pngquant --ext <suffix> <image.png> — Set output file suffix (default: -fs8.png).

pngquant --ext -small.png screenshot.png

pngquant --strip <image.png> — Strip all metadata from output.

pngquant --strip photo.png

pngquant - < <input.png> > <output.png> — Read from stdin, write to stdout (for piping).

cat input.png | pngquant - > output.png

pngquant --verbose <image.png> — Show detailed processing info (remapped colors, file sizes).

pngquant --verbose screenshot.png

Common 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/*.png

find . -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.png

pngquant 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.png

for 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

  • optipng – lossless PNG optimizer that pairs perfectly with pngquant
  • gifsicle – create and optimize animated GIFs
  • convert – convert and edit images with ImageMagick