About me: My name is Solène Rapenne, pronouns she/her. I like learning and sharing knowledge. Hobbies: '(BSD OpenBSD Qubes OS Lisp cmdline gaming security QubesOS internet-stuff). I love percent and lambda characters. OpenBSD developer solene@. No AI is involved in this blog.

Contact me: solene at dataswamp dot org or @solene@bsd.network (mastodon).

I'm a freelance OpenBSD, FreeBSD, Linux and Qubes OS consultant, this includes DevOps, DevSecOps, technical writing or documentation work.

If you enjoy this blog, you can sponsor my open source work financially so I can write this blog and contribute to Free Software as my daily job.

Port of the week: pngquant

Written by Solène, on 07 September 2021.
Tags: #graphics #unix #portoftheweek

Comments on Fediverse/Mastodon

1. 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

2. 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.

$ pngquant file.png
$ test -f file-fs8.png && echo true

3. 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.

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.

4. 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.