Install pngquant on Ubuntu 20.04

The pngquant is a tool which allows to compress PNG images via command line. In order to reduce the size, images are converted to 8-bit PNG format with alpha channel. Usually, 8-bit PNG images are 60-80% smaller than 24/32-bit PNG images.

This tutorial explains how to install pngquant on Ubuntu 20.04.

Install pngquant

Update the package lists:

sudo apt update

Run the following command to install pngquant:

sudo apt install -y pngquant

When installation is finished, we can check pngquant version:

pngquant --version

Testing pngquant

Download image for testing:


Run the pngquant command and provide image name as argument to compress the image.

pngquant test.png

By default, the output filename is the same as input filename except it ends with -or8.png or -fs8.png suffix.

ls -l
-rw-rw-r-- 1 adminer adminer 10427 Jan 18 02:25 test-fs8.png
-rw-rw-r-- 1 adminer adminer 17194 Jan 18 02:13 test.png

As we can see, an image is ~61% smaller than the original image.

The -o option can be used to provide the output filename.

pngquant test.png -o result.png

Using --quality option with min-max value we can specify the output image quality in range 0 (worst) to 100 (perfect). If the image quality after compression is below than min, output image will not be saved. In order to compress image, pngquant uses fewer colors below than max. If the --quality option is omitted then default behavior is equal to --quality=0-100.

The --force option can be used to overwrite existing output file.

pngquant --quality=60-70 --force test.png

Uninstall pngquant

If you decided to completely remove pngquant and related dependencies, run the following command:

sudo apt purge --autoremove -y pngquant

Leave a Comment

Your email address will not be published.