Pngquant, command line utility for compressing PNG images

aboutpngquant

In the next article we are going to take a look at pngquant. This is a lossy PNG compressor to use from the command line. It's free, open source, and cross-platform. This program will give us the possibility to convert PNG images to an 8-bit PNG format with an alpha channel file to reduce the size.

This image compressor Free png is based on a portable library libimagequant and it's written in C99. Significantly reduces file size by converting PNG image to a more efficient 8-bit PNG format, preserving full alpha transparency. 8-bit PNG files are typically 60-80% smaller than 24/32-bit PNG files. Pngquant compressed images are fully compatible with all web browsers and operating systems. Furthermore, this software can compress one or several images at the same time.

Pngquant general features

  • In this lossy PNG compressor.
  • It is based on a libimagequant portable library.
  • Makes PNG images 3-4 times smaller with minimal loss of quality.
  • supports alpha transparency.
  • Es compatible with all browsers and systems operational.
  • Generates high quality pallets.
  • It uses a unique interpolation algorithm that does not add unnecessary noise to the image.
  • The quality level is configurable.
  • Automatically find the required number of colors and you can skip images that cannot be converted to the desired quality.

These are just some of the characteristics of this compressor for the command line. All of them can be consulted in more detail in the GitHub page of the project or in its site.

Install pngquant PNG compressor using snap

Ubuntu users will be able to install Pngquant compressor using its corresponding snap package. For this example, in Ubuntu 18.04 we will only have to open a terminal (Ctrl + Alt + T) and write the following installation command in it:

install pngquant snap

sudo snap install pngquant

Basic use

After installation we can start using pngquant. We will can use the program as follows to compress a png file:

pngquant nombre-del-archivo.png

For example, if we wanted compress a file a file named ubunlog. Png which in this case I have in the Images folder, we will have to execute the following commands:

cd Imágenes

Before compression we will view file size with the command:

uncompressed image size

du -sh ubunlog.png

After seeing the size in the previous screenshot, which in this case is 16K, we can now start compression with the command:

pngquant compressed image

pngquant ubunlog.png

The output file name in this example is the same as the input name, except that will end in '-fs8.png'. As you can see in the previous screenshot, in this example the name of the output file will be 'ubunlog-fs8.png'

Now let's see the size of the compressed image file, which in this example was reduced to 8K:

compressed image size

du -sh ubunlog-fs8.png

Compress multiple PNG images

Pngquant too can convert multiple images. The following command will compress image1.png y image2.png in the current working directory.

pngquant imagen1.png imagen2.png

In addition, we can compress all .png files located in a directory at once. For example, to compress all images within a folder called '/ home / entreunosyceros / Images', we will execute:

batch compression

pngquant /home/entreunosyceros/Imágenes/*.png

Change suffix in output file name

As I already said, the name of the output file is the same as the input name, except that it ends in '-fs8.png'. Nevertheless, we will be able to change this suffix as we want as follows:

change the suffix of the resulting image

pngquant ubunlog.png --ext -imagen.png

This command will compress the file ubunlog. Png and save it as ubunlog-image.png.

Compress images in custom quality

Pngquant compresses the images as much as possible. We can also manually configure the quality of the images. Pngquant allows us to set the image quality in the range 0 (worst) to 100 (perfect) using the minimum and maximum parameters.

The following example sets the quality of minimum image at 60 and maximum quality at 80.

change image quality

pngquant --quality=60-80 image.png

If the conversion produces a quality lower than the minimum quality, the image will not be saved.

Pngquant Help

These commands are just a few examples of basic compression using pngquant. We will be able see the full list of available options running the following command in the same terminal:

help pngquant

pngquant -h

Leave a Comment

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

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.