Install pngquant on Ubuntu 22.04

Install pngquant on Ubuntu 22.04

The pngquant is a tool which allows compressing PNG images via command line. 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 22.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:

wget https://raw.githubusercontent.com/kornelski/pngquant/master/test/img/test.png

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 the input filename, except it ends with -or8.png or -fs8.png suffix.

ls -l
-rw-rw-r-- 1 adminer adminer 10248 Dec  7 02:26 test-fs8.png
-rw-rw-r-- 1 adminer adminer 17194 Dec  7 02:26 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, the output image will not be saved. To compress the 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 an 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

Cancel reply

Your email address will not be published.