PNG screenshots and diagrams can be smaller without changing their dimensions. On Linux, pngquant compresses a PNG into a separate copy for comparing size, image quality, and transparency.
pngquant reduces a true-color PNG by writing a palette-based PNG that can still keep transparency. The result remains a standard PNG that image viewers and browsers can open.
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 choosing to replace the source image.
Steps to compress a PNG with pngquant in Linux:
- Refresh the package index on Ubuntu or Debian.
$ sudo apt update
The APT prerequisite commands apply to Ubuntu and Debian. On other distributions, install the pngquant package through the distribution's package manager.
- Install pngquant on Ubuntu or Debian.
$ sudo apt install pngquant
- Open the directory that contains the PNG file.
$ cd ~/images
The filename sample.png stands for the PNG to compress.
- Write a compressed review copy.
$ pngquant --quality=65-85 --skip-if-larger --strip --output sample-compressed.png sample.png
--quality=65-85 targets a quality score of 85 and refuses results below 65; these scores are not percentages of the original file size. --strip removes optional PNG metadata, and --output leaves the source file untouched.
- Compare the compressed copy with the original in an image viewer.
Edges, text, gradients, and transparent areas need visual comparison, including against light and dark backgrounds. Replacing the original is optional and requires a backup to retain its full-color data.
Do not replace the source image when banding, halos, text fuzziness, or transparency changes are visible in the compressed copy.
- Compare the source and compressed file sizes.
$ ls -lh sample.png sample-compressed.png -rw-r--r-- 1 user user 181K Nov 5 19:04 sample-compressed.png -rw-r--r-- 1 user user 740K Nov 5 19:04 sample.png
A smaller sample-compressed.png with acceptable image quality is the result to keep; the original sample.png remains available. If ls reports that sample-compressed.png does not exist, pngquant saved no copy, so keep the original: exit status 98 means the size reduction did not justify the quality loss, and 99 means the minimum quality could not be met.