[Feat]: sharp
support for animated webp/gif
#26526
Replies: 13 comments
-
Thank you for creating this feature request. I'm not sure we should add an animated gif/webp as it has a performance impact and could lead to a battery drain. If we want to hold up to our "performance"/accessbility value we should convert these gifs into video format. More info https://web.dev/replace-gifs-with-videos/ Open to thoughts / ideas |
Beta Was this translation helpful? Give feedback.
-
That would be up to the developer and to a degree the browser. We can add support for the reduced motion preference, I assume that browser software on mobile could optimize for that when they see fit, like they do with other network activity, native image lazy loading, and support for dark/light theme matching the system OS preference. Docs can continue to advise/caution against such, but if a user is going to ignore that and manually reach out for For those that actually take more time to read the docs, if they'd want to go through additional effort to switch to video as we can advise, great.
That's a bigger effort to support, introduces additional maintenance effort and complexity where more could go wrong? It'd be wiser to raise this as a warning in I am well aware of how bad If we stick to animated image formats which would suit Here is a insightful article comparing GIF, APNG, WEBP and MP4/WEBM. A ~40MB GIF becomes a ~30MB WEBP, but with quality settings can be lowered down to ~5MB. That's still quite a bit, although it does depend on the content/frames for how well the data can be optimized. The MP4 optimized is only ~500KB and the WEBM a mere ~200KB. GIF was optimized down to ~20MB in a related article. Not against the conversion, but probably shouldn't be implicit. It'd be easier to just go with the animated image support for now, and consider conversion and TL;DR
|
Beta Was this translation helpful? Give feedback.
-
Version 0.26 of sharp has been officially released if anyone wants to tackle a PR for this. |
Beta Was this translation helpful? Give feedback.
-
I'd like to hop on this one. Will do some research and report back |
Beta Was this translation helpful? Give feedback.
-
@han-so1omon sorry if you've dived into this already, there will be a blocker with resizing animated images: lovell/sharp#2275 Apparently for now it can be done with an explicit You may also find that at least for operations on Perhaps though, the MP4/WEBM route would be better in that case, but not being able to leverage existing |
Beta Was this translation helpful? Give feedback.
-
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Beta Was this translation helpful? Give feedback.
-
not stale |
Beta Was this translation helpful? Give feedback.
-
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Beta Was this translation helpful? Give feedback.
-
I'm needing this feature. Currently using |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm here because we would appreciate animated lossless image formats a lot. Concerning "should all be video format": I agree that 95% of the animated gifs of the world would be better stored as WebM / MP4. But just like authors have to deliberately choose between PNG and JPEG (lossless / lossy) for good reasons that choice is important for content like screenshot sequences too. Screenshots of Software and web UIs are effectively line graphics, often with hair lines and they are simply not a good fit for video formats. I do not think the site generator should prescribe the usage of lossless vs. lossy media format choices. Whether something is a good practice, accessible etc. can only partially evaluated in technology. Defaults and accessibility / performance warnings are important here (e.g. no looping, maybe no animation support without a config flag at all), but the tech stack is still a tool and not the author. Concerning gif vs. apng vs. animated webp: It could be considered to only (or at least first) bother about WebP here.
Initializing sharp with |
Beta Was this translation helpful? Give feedback.
-
It depends, it's not always that bad and can be a valid option when you need it without better alternatives available to use.
That hasn't discouraged supporting other features depending on binaries in the past, mozjpeg comes to mind IIRC depending on platform (libvips was a bit of an issue back then too though).
Support in Safari is very recent(also requires latest macOS from this year to use, iOS also only the latest). IE (including Edge before the switch to Chromium base) might also be somewhat important, as small of a demographic it can be to many, depending on industry/region it's sometimes a requirement to support still and Gatsby tries not to "break" when it's possible to support fallbacks. It might surprise you, but we've had things like TLS 1.2 since 2008, which was more broadly available to deploy around 2012-2014. It's only in 2020 that previous protocol versions have been deprecated by browsers, with mail servers due to different environments they lag a bit more behind still. Apple had TLS 1.2 support with iOS 5 I think, but only for HTTPS, other protocols like SMTP and IMAP with explicit and implicit TLS didn't receive that until iOS 9 (2015), yet there are users still stuck on that (including some on Android 4.x where TLS 1.2 even for HTTPS lacks).
Sure 👍 Something is better than nothing. If it turns out to be easier to implement just for WebP, but someone has to put in the time. Since it'll be tailored to Gatsby, we may have to wait until it's prioritized by a paid developer being assigned. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the response @polarathene ! You caught me a bit on my learnt objection to gifs, until July 2004 you were sued for it so that seems to still be in my mind. Also, I did forget to give enough context to the "don't convert to gif": I don't think that original files in animated WebP or PNG should be converted into animated gifs for browser compatibility reasons (the color range is restricted, even with optimizations). But if the author provides an animated gif it would be good to keep it in gif format if the necessary library is provided. Like today, WebP original files stay being delivered as WebP files in the built site even without explicitly setting the webP option to true.
Anybody can provide a PR but I agree it would be good to have positive feedback on the conceptual approach from a gatsby staff member before putting work into it. |
Beta Was this translation helpful? Give feedback.
-
Need something like this. There is some crossover between this discussion and #29410 which discusses gifs. One thing I would also need is a format supporting alpha channel which mp4 does not. I have a project where the designer has given me |
Beta Was this translation helpful? Give feedback.
-
Summary
In an upcoming
0.26
release ofsharp
, support for animated webp and gif will be available.Motivation
gatsby-image
doesn't presently support animated images and advises using plain<img>
instead, but that was due to a limitation with support insharp
.A related doc on gif usage also raises awareness regarding autoplay, while this article shows how the picture element can use a media condition to present a static image if the user has preferred reduced motion.
There's also some code in
gatsby-transformer-sharp
that may need to be updated should this feature be added.Beta Was this translation helpful? Give feedback.
All reactions