Install pngquant on Raspberry Pi

Install pngquant on Raspberry Pi

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

This tutorial explains how to install pngquant on Raspberry Pi.

Use SSH to connect to Raspberry Pi. Update the package lists and install pngquant by using these commands:

sudo apt update
sudo apt install -y pngquant

Once installation is complete, we can check pngquant version:

pngquant --version

For testing purpose download image from the Internet:

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

Now execute the pngquant command to compress the image. The name of the image is specified as argument.

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-r--r-- 1 pi pi 10427 Mar  3 04:55 test-fs8.png
-rw-r--r-- 1 pi pi 17194 Mar  3 04:51 test.png

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

We can use -o option to specify the output filename.

pngquant test.png -o result.png

The output image quality can be specified in range 0 (worst) to 100 (perfect) by using --quality option with min-max value. If the image quality after compression is below than min, output image will not be saved. The pngquant will use fewer colors below max to compress the image. If the --quality option is omitted then default behavior is equal to --quality=0-100.

The --force option allows to overwrite existing output file.

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

If you want to completely remove pngquant and related dependencies, execute the following command:

sudo apt purge --autoremove -y pngquant

The 1 Comment Found

  1. Avatar
    Hwa Buntine Reply

    Hello lindevs.com admin, Your posts are always well-supported by facts and figures.

Leave a Comment

Cancel reply

Your email address will not be published.