PNG screenshots, interface mockups, and diagrams often move through tickets, repositories, and web deployments where avoidable bytes slow reviews or trigger upload limits. Compressing the file in place too early can hide color loss, so start with a separate reduced copy and compare it before replacing the original.
pngquant reduces a true-color PNG by writing a palette-based PNG that can still keep transparency. The --output option names a review copy, --strip removes optional metadata chunks, and --skip-if-larger avoids saving a result that does not reduce the file enough to justify the conversion.
The conversion is lossy because fewer colors are stored. Screenshots, diagrams, and flat interface assets usually tolerate this better than photos, gradients, or artwork with subtle shading, so visual review remains part of the workflow before any command overwrites the source image.
$ cd ~/images
Without --output or --ext, pngquant writes its converted file beside the source image with a suffix such as -fs8.png or -or8.png.
$ ls -lh sample.png -rw-r--r-- 1 user user 2.0M Jun 13 2026 sample.png
$ pngquant --quality=65-85 --skip-if-larger --strip --output sample-compressed.png sample.png
--quality=65-85 keeps the result above the minimum quality score, --strip removes optional PNG metadata, and --output leaves the source file untouched.
$ ls -lh sample.png sample-compressed.png -rw-r--r-- 1 user user 15K Jun 13 2026 sample-compressed.png -rw-r--r-- 1 user user 2.0M Jun 13 2026 sample.png
If pngquant exits with status 98, the converted file was not worth saving. Status 99 means the requested minimum quality could not be met.
$ file sample-compressed.png sample-compressed.png: PNG image data, 960 x 540, 4-bit colormap, non-interlaced
A colormap result is expected when pngquant reduces the image to a smaller palette.
Do not replace the source image when banding, halos, text fuzziness, or transparency changes are visible in the compressed copy.
$ pngquant --quality=65-85 --skip-if-larger --strip --ext .png --force sample.png
--ext .png with --force writes back to the original path.
$ ls -lh sample.png -rw-r--r-- 1 user user 15K Jun 13 2026 sample.png