Install pngquant from Source Code on Raspberry Pi

The pngquant is a tool that allows to compress PNG images via command line.

On Raspberry Pi, use the APT package manager to install pngquant unless you want to install the latest version of pngquant. This tutorial explains how to install pngquant from source code on Raspberry Pi.

Prepare environment

The pngquant depends on libpng library. So install libpng-dev package which provides the development headers.

sudo apt update
sudo apt install -y libpng-dev

To compile pngquant, we need to install build-essential package.

sudo apt install -y build-essential

Compile and install pngquant

Navigate to your home directory and download the source code of pngquant from GitHub repository. Then go to the pngquant source directory.

cd ~
git clone --recursive https://github.com/kornelski/pngquant.git
cd pngquant

Use the make command to compile pngquant. The -j option defines the number of jobs to run in parallel.

make -j$(nproc)

Now install pngquant as a system-wide command with make install:

sudo make install

When installation is finished, check pngquant version:

pngquant --version

There is no longer need to keep the source code. We can remove it:

cd ~
sudo rm -rf pngquant

Also we can remove the development headers:

sudo apt purge --autoremove -y libpng-dev

Testing pngquant

Download image from the Internet:

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

Now compress image with pngquant command:

pngquant test.png

Uninstall pngquant

If you wish to completely remove pngquant, delete the following files:

sudo rm -rf /usr/local/bin/pngquant
sudo rm -rf /usr/local/share/man/man1/pngquant.1

You can also uninstall build-essential and related dependencies:

sudo apt purge --autoremove -y build-essential gcc g++ make

Leave a Comment

Your email address will not be published. Required fields are marked *