imgproxy / imgproxy

Fast and secure standalone server for resizing and converting remote images
https://imgproxy.net
MIT License
9.03k stars 633 forks source link

Feature request: add support for APNG animated images #1222

Open SmaugPool opened 1 year ago

SmaugPool commented 1 year ago

APNG is now supported by all modern browsers: https://caniuse.com/apng

For now only the first frame of APNG animated images is considered by imgproxy as the format is backward compatible with PNG. It would be great to be able to resize them as animated images when IMGPROXY_MAX_ANIMATION_FRAMES > 1.

Some patches are available for libpng, but it seems that libvips is waiting for libpng official support, itself waiting for libspng support, which is in progress:

libvips support: https://github.com/libvips/libvips/discussions/2000 libpng support: https://github.com/glennrp/libpng/issues/267 libspng support: https://github.com/randy408/libspng/projects/3

DarthSim commented 1 year ago

Hey @SmaugPool!

I don't think APNG makes much sense nowadays, especially in the context of imgproxy:

  1. We have WebP. It's highly effective, widely supported, and has a lossless mode. But if your goal is to optimize your GIFs, you most probably don't need lossless mode.
  2. APNG is even less effective than GIF. I have a 25 MB GIF (616x451, 207 frames). APNG created from this GIF is 32 MB. Lossless WebP created from the same file is 23, and lossy one – 4.5 MB.
  3. Compression to APNG is extremely slow. It takes more than 4 min to convert that 25 MB GIF to APNG using FFmpeg. For comparison: its conversion to lossless WebP takes just 13 seconds, to lossy WebP – 5 seconds.

The main goal of APNG was full-color animations. However, the overwhelming majority of animations are still served as GIFs or MP4 created from GIFs. Actually, I didn't see a single APNG in the wild.

SmaugPool commented 1 year ago

Thank you for your answer @DarthSim, I know about existing formats and most of their pros/cons.

I should have precised that my current use case is to transcode & rescale APNG to animated WebP/AVIF, not to get an APNG output.

As you know very well from all its security features, imgproxy is also used for use cases where the source image comes from users and is not controlled. And APNGs definitely exist in the wild, for example in the NFT ecosystem (I guess because it's lossless with great browser support and backward compatible with PNG so supported at least without animation by basically all image applications). See for example this APNG collection (right save if you want to check): https://www.jpg.store/collection/chainsondogs

That said for sure APNG is not trending so I understand supporting it is far from a priority. But once it is natively supported in libvips, maybe supporting it at least for inputs will be a low effort enough to make sense. Until then this issue can provide information for those wondering about the status of APNG support.

SmaugPool commented 1 year ago

@DarthSim For information, I asked more about it and one of the main reasons APNG is still used instead of Lossless Animated WebP is because Discord still does not support Animated WebP.

For some projects, the ability to share media on social networks is very important and Discord is used a lot currently.

https://support.discord.com/hc/en-us/community/posts/360034605072-Add-support-for-WEBP-Animated-Images-and-Emojis

https://github.com/discord/lilliput/pull/103