Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to set sharp's animated option #456

Open
sskylar opened this issue Mar 17, 2023 · 3 comments
Open

Allow user to set sharp's animated option #456

sskylar opened this issue Mar 17, 2023 · 3 comments

Comments

@sskylar
Copy link

sskylar commented Mar 17, 2023

Right now sharp's animated option is turned on automatically if contentType is GIF:

const options = { failOnError: false, animated: imageRequestInfo.contentType === ContentTypes.GIF };

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 animated to their preference (true or false).
@dougtoppin
Copy link
Member

@sskylar Adding this to our backlog to evaluate. We will get back to you. Tks for the idea and details.

@vaniyokk
Copy link

vaniyokk commented Oct 12, 2023

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

@simonkrol
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants