htop icon indicating copy to clipboard operation
htop copied to clipboard

Optimize images to reduce filesize

Open anthonyryan1 opened this issue 3 years ago • 8 comments

It's a small change, but I've losslessly compressed the htop logo to save half a kilobyte on every computer it's installed on.

anthonyryan1 avatar Jul 20 '22 20:07 anthonyryan1

Which program did you use to optimize the images?

Explorer09 avatar Jul 24 '22 10:07 Explorer09

The images were optimized using zopflipng a subproject of Google's zopfli

anthonyryan1 avatar Jul 24 '22 22:07 anthonyryan1

@anthonyryan1 I've heard of zopflipng, but I usually optimize PNG image using a combination of OptiPNG, Advdef (with "zopfli" compression level), and DeflOpt.

Explorer09 avatar Jul 25 '22 02:07 Explorer09

@Explorer09 Thanks for sharing your compression recommendations. I did take a look for comparison.

With this image in particular:

  • OptiPNG couldn't outperform zopflipng with any combination
  • Advdef was able to outperform zopflipng by 1 byte after 20,000 iterations

I couldn't find any information on which package provides DeflOpt to give that a fair test. What package is that a part of, or can you link me to a source repository I can compile it from for testing?

So far all I've saved in 1 byte, but if we can do better I'm more than open to doing so.

anthonyryan1 avatar Jul 25 '22 03:07 anthonyryan1

I did manage to squeeze out some extra bytes using https://github.com/fhanau/Efficient-Compression-Tool

I've amended the commit, and nothing I've run can seem to do better.

anthonyryan1 avatar Jul 25 '22 03:07 anthonyryan1

I am not sure the zopfli compression is widely supported. Did you test on - say - Android 4.4 or other ancient-but-still-widely-used browsers / OS?

People should still be able to browser the website and docs even if their employer has the typical update cycles of regional governments :).

fasterit avatar Jul 26 '22 13:07 fasterit

I haven't tested this image, but I have been using it on other images since 2013 and never had an issue with Android 4.4 back when it was still widely used.

Zopfli doesn't introduce compatibility issues, it maintains compatibility with all deflate decoders at the expense of not being as good as some newer compression formats.

anthonyryan1 avatar Jul 26 '22 14:07 anthonyryan1

@fasterit Zopfli is an encoder only and it's compatible with any DEFLATE decoder, Zopfli is, as far as I can see, the most aggressive DEFLATE-compatible encoder on the internet. It's slow and it's meant for compressing "offline" content.

@anthonyryan1 DeflOpt is here (https://encode.su/threads/3257-Deflopt). It's a little tool for optimizing an already compressed stream, and it is meant to be used after a compression tool like zopflipng, to squeeze out a byte or two on the compressed file.

I can't comment about Efficient Compression Tool yet. But I would like to tell that some online image optimizers like TinyPNG is actually lossy optimizer and you should stay away from it unless you know what you are doing.

Explorer09 avatar Jul 30 '22 10:07 Explorer09

@anthonyryan1 I played around with the Efficient Compression Tool you mentioned, and I was able to squeeze a few more bytes for the htop icon and the screenshot picture.

$ ect -9 -keep --strict --allfilters --pal_sort=120 screenshot.png
Processed 1 file
Saved 4B out of 45.07KB (0.0087%)

$ DeflOpt.exe -b -d -c -k screenshot.png

Number of bytes saved: 2 (46,144 --> 46,142)
File rewritten.

Number of files processed  :        1
Number of files rewritten  :        1
Total number of bytes saved:        2
23,606,371 cycles.

$ ect -9 -keep --strict --allfilters --pal_sort=120 htop.png
Processed 1 file
Saved 487B out of 3.03KB (15.6945%)

After ECT, I can't squeeze more bytes on htop.png with DeflOpt. And here you go, the optimized pictures in a zip file

Explorer09 avatar Aug 23 '22 04:08 Explorer09

Amended to incorporate your further optimized images!

anthonyryan1 avatar Aug 28 '22 14:08 anthonyryan1