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:
After it is installed, it can be directly used from the Terminal. Here is how:
To compress an existing PNG image, the syntax is:
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.
You can check the compression by comparing the sizes of the original and processed images.
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:
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:
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:
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.
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.
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:
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.