Title: Port of the week: pngquant | |
Author: Solène | |
Date: 07 September 2021 | |
Tags: graphics unix portoftheweek | |
Description: | |
# Introduction | |
Today as a "Port of the Week" article (that isn't published every week | |
now but who cares) I would like to present you pngquant. | |
pngquant is a simple utility to compress png files in order to reduce | |
them, with the goal of not altering the file in a visible way. | |
pngquant is lossy which mean it modify the content, at the opposite of | |
the optipng program which optimize the png file to try to reduce its | |
size as possible without modifying the visual. | |
pngquant project website | |
# How to use | |
The easiest way to use pngquant is simply give the file to compress as | |
an argument, a new file with the original file name with "-fs8" added | |
before the file extension will be created. | |
```shell commands | |
$ pngquant file.png | |
$ test -f file-fs8.png && echo true | |
true | |
``` | |
# Performance | |
I made a simple screenshot of four terminals on my computer, I compared | |
the file size of the original png, the png optimized with optipng and | |
the compressed png using pngquant. I also included a conversion to jpg | |
of the same size as the original file. | |
I used defaults of each commands. | |
```table with results | |
File size (in kilobytes) % of original (lower is better) | |
======== =============== =============================== | |
original 168 100 | |
optipng 144 85.7 | |
pngquant 50.2 29.9 | |
jpeg 71% 169 100 | |
``` | |
The file produced by pngquant is less than a third of the original. | |
Here are the files so you can try to check if you see differences with | |
the pngquant version. | |
* Original file | |
Original file | |
* Optimized file | |
Optimized file using optipng | |
* Compressed file | |
Compressed file using pngquant | |
* Jpeg conversion (targeting same size) | |
Jpeg file converted with ImageMagick | |
# Conclusion | |
Most of the time, compressing a png is suitable for publishing or | |
sharing. For screenshots or digital pictures, jpg format is usually | |
very bad and is only suitable for camera pictures. | |
For a drawn picture you should keep the original if you ever plan to | |
make changes on it. |