XL Converter
Update: I wrote XL Converter, which automates this process entirely. Just select “Smallest Lossless”.
Comparison
Here are sample results on what kind of savings you may expect from each format.
Format | Filesize | Runtime |
---|---|---|
PNG (Unoptimized) | 100% | – |
PNG (Optimized) | 68.8% | fast |
WEBP | 54.6% | fast |
JPEG XL | 51.7% | normal |
JPEG XL (effort 9) | 46.4% | very slow |
Converter
The most popular converter is XnConvert. It’s robust, easy to use and features some quality of life improvements you might need.
You change the format by going to the Output tab. In the settings, you will find the lossless mode.
You should enable “Use multiple CPU Cores” for faster transcoding. Keep at least 1 core unused to avoid freezes.
Note for Linux users: use the JPEG XL binaries instead.
Now, I will discuss what format you should choose and why.
JPEG XL
If you don’t care about compatibility and just want the smallest possible size, you should use JPEG XL. It will work well for archival purposes.
The tradeoff is you will need a compatible program to open it (like XnViewMP). Web browsers won’t open it.
Optimization
You can save extra ~5% of the filesize by increasing the effort. Transcoding will take over 10 times longer so it’s not recommended.
Go to the format settings and set “compression” to 9. The default is 7.
WEBP
Use this format If you’re planning on displaying lossless images in browser. The caveat is the images cannot be larger than 16384 pixels in any dimension.
I tried to use AVIF for this purpose, but the size often ended up being 2 – 3 times larger than the original PNG.
Optimization
You can save additional ~3% of the filesize by changing the method. Again, it will make transcoding much slower so it’s not recommended.
Go to the format settings and change the method from 4 to 6.
PNG Optimizations
If you desperately need to keep the files in PNG, you can still shave off some filesize by recompressing it.
Method | Filesize | Runtime |
---|---|---|
Zopfli (advpng) | 91.1% | very slow |
OxiPNG -o 4 | 68.8% | fast |
Zopfli
Download advpng and install it in your system PATH. Here is how to use it:
advpng -z4 source.png
This is how you recompress all PNGs in your directory.
advpng -z4 *.png
Zopfli takes a much longer time to transcode than JPEG XL or WEBP.
OxiPNG
OxiPNG is much faster than Zopfli and will shrink your PNGs more.
However, it can reduce bit depth, color type and palette. If you don’t want to alter those, stick with Zopfli.
Install OxiPNG to your system PATH. You use it like this:
oxipng -o 4 source.png
Batch transcoding works the same way as it does in advpng
oxipng -o 4 *.png
You can set the compression higher (-o max
), but it rarely produces better results and is much slower.
There is also the -Z
flag that may save you addition 1% – 2%, but it’s so slow, it’s hardly worth it.