November 4, 2024

To optimize PNG images in Linux Mint using the command-line, pngquant is a useful tool. It uses the Floyd-Steinberg dithering algorithm to achieve compression and reduce the image size.

Install it by opening the Terminal and typing in:

sudo apt install pngquant

installing pngquant in linux mint

After it is installed, it can be directly used from the Terminal. Here is how:

To compress an existing PNG image, the syntax is:

pngquant imagename

In this example, an image named mint.png is compressed using pngquant. By default, pngquant adds suffixes like fs8.png and or8.png to the output images.

compressing png images using pngquant

You can check the compression by comparing the sizes of the original and processed images.

compressed v/s original png images by using pngquant

Different parameters can be used with pngquant, here is how to use the common ones:

Remove metadata:

To remove chunks of metadata from the original PNG image during processing, use the –strip option:

pngquant --strip imagename

stripping metadata chunks from processed images using pngquant

Add custom suffixes:

By default, all the processed PNG images have the fs8.png or or8.png suffixes added to them once processed. To use any other custom suffix, the –ext parameter can be used:

pngquant --ext 'new suffix' imagename

using a custom suffix for compressed images using pngquant

In this example, a custom suffix -compressed.png is used, so the output image has that added to it after processing.

Overwrite existing processed images:

To overwrite existing processed images (not the source or original ones), use the –force parameter:

pngquant --force imagename

overwrite processed images using pngquant

In this example, the earlier processed image was overwritten with a new one but with the same name as seen from the timestamp.

Batch process multiple images:

pngquant can also compress different PNG images in one go. Specify the individual image names to be compressed if only a few are to be processed.

batch processing multiple png images using pngquant

You can also use a wildcard to process all the existing PNG images. The output images will have the default suffixes added once processed and with a reduced size.

selecting all png images for processing using pngquant

There are other parameters too like –quality, –speed, –floyd, and so on for changing the dithering and quality settings.

A quick list of available parameters can be viewed using the man command:

man pngquant

pngquant man pages

It is a useful command-line tool for compressing PNG images and also supports batch processing. For other types, using imagemagick can also be handy.

Happy compressing.

By admin

Related Post