Allow user to set sharp's `animated` option
Right now sharp's animated option is turned on automatically if contentType is GIF:
https://github.com/aws-solutions/serverless-image-handler/blob/182641250578bf2b921034e8d4b061ca5f5e96ce/source/image-handler/image-handler.ts#L78
This should be user customizable.
Use cases:
- Removing animation from GIF (
animated: false) - Enabling animation for other formats such as WebP (
animated: true)
Animated WebP files are supported by sharp (example), but this setting is preventing it from working.
Solution:
- Keep the current default, but allow user to optionally set/override
animatedto their preference (trueorfalse).
@sskylar Adding this to our backlog to evaluate. We will get back to you. Tks for the idea and details.
We are encountering the same issue.
We are utilizing the AUTO_WEBP feature and anticipate all images to be converted to WebP, including GIFs while preserving their animations.
Sharp provides the capability to achieve this, but we lack the ability to use the animated flag, and it consistently remains false when using AUTO_WEBP due to the Content-Type check.
This is occurring because imageRequestInfo.contentType is continually overwritten with imageRequestInfo.outputFormat as shown in the following code snippet:
imageRequestInfo.contentType = `image/${imageRequestInfo.outputFormat}`;
https://github.com/aws-solutions/serverless-image-handler/blob/main/source/image-handler/image-request.ts#L74
The subsequent check for 'contentType' is nearly redundant, unless your intention is to receive GIF in output, but it's a rare case, because GIF is not an optimal choice.
const options = { failOnError: false, animated: imageRequestInfo.contentType === ContentTypes.GIF };
https://github.com/aws-solutions/serverless-image-handler/blob/main/source/image-handler/image-handler.ts#L78
It's possible that this check was initially designed to use the original image's Content-Type, and convert animated GIF to animated WEBP but it currently does not achieve that purpose.
cc @simonkrol
Hi @sskylar, We've decided to include a new filter which allows for overriding the animated flag passed into Sharp. You can read more about it here. We plan to have this feature included in the next minor/major release.
Thanks for your interest in Serverless Image Handler, Simon
Fixed in v6.2.6 to allow the use of the filters:animated(true/false) tag for Thumbor style requests, or the animated: true/false edit for base 64 encoded requests.