hadrien-psydk / pngoptimizer

Optimize PNG images and convert other lossless format (BMP, GIF, TGA...) images to PNG
123 stars 16 forks source link

feature_request(apng): --lossy option #14

Open Kristinita opened 4 years ago

Kristinita commented 4 years ago

1. Summary

It would be nice, if PngOptimizerCL will compress .apng files 2 times or more.

It's okay if with a loss of images quality.

2. Argumentation

2.1. Common cause

Using .apng files in real practice.

2.2. Details

I pasted real .apng images on web forums, discussions and so on. Unfortunately, on May 2020 I can't use big .apng files, because users, that don't have power computers, may have problems.

No, I don't make .apng “Avatar”. See one my example: one 15 second .apng file have 35.7 Mb size (.gif — 7,6; .mp4 — 2.1). So usage .apng on web currently is very limited.

I agree, if my images would have the worst quality, but that they could be used in the web.

3. Example of expected behavior

For .gif see giflossy, that implemented to gifsicle as --lossy option. See the table — it compressed original .gif file 4 times (!) without serious quality loss.

It would be nice to have similar behavior for .apng

4. Example results

4.1. Data

my old 4 .apng files, that I created by ScreenToGIF.

4.2. Current behavior

D:\SashaDebugging\KiraPngOptimizerCL>pngoptimizercl -file:"*" -BackupOldPngFiles
Optimizing KiraAnaconda.apng [APNG]  (OK) 3049013 bytes -> 2677164 bytes (87% of the original size)
Optimizing KiraEasygit.apng [APNG]  (OK) 944183 bytes -> 828899 bytes (87% of the original size)
Optimizing KiraGitHubEmoji.apng [APNG]  (OK) 1542760 bytes -> 1348392 bytes (87% of the original size)
Optimizing KiraMahou.apng [APNG]  (OK) 14856851 bytes -> 12165151 bytes (81% of the original size)
-- Done --  91750 ms 20392807 bytes -> 17019606 bytes (83% of the original size)

4.3. Expected behavior

pngoptimizercl --lossy=200 KiraExampleApng.apng

And user will get 50% of original size or even less.

5. It might help

See libimagequant .png library from giflossy author, that used in pngquant CLI utility.

Unfortunately, it doesn't support .apng.

Thanks.

hadrien-psydk commented 4 years ago

Привет Саша,

This looks like an interesting use-case. However I am not sure if PngOptimizer is the best project for that, because since its creation the design goal has been to be a visually lossless tool.

Anyway, it would be interesting to implement your suggestion as a new project. Thank you for the links, they can be useful to avoid reinventing the wheel.

vatterspun commented 4 years ago

The use case of animated PNG files is that if you need to go back in and modify an animation, it's much easier. It's one of the reasons GIF files survived for so long -- basically the Internet wants to borrow from or change existing content. This isn't even an option with many video file types that become un-viewable junk by the 2nd or 3rd compression effort.

What might be a good balance is a reduced color level. GIF files are stuck at 256 colors, while PNG can have a 10,000 pixels all with different colors, making them 10x the size of the same poorly compressed GIF recording.

As such, I thought it might be a good balance between the two options to enable reduced color depth, which definitely qualifies as "lossy." This is not an original idea on my part https://en.wikipedia.org/wiki/Portable_Network_Graphics#Lossy_PNG_compression.

Unfortunately, I've noticed that some animations I've converted from animated GIF to animated PNG format using pngoptimizer are actually larger than when I just convert to native animated PNG. This has happened several times, usually with basic, animated screen recording demonstrations.