serverless-image-handler icon indicating copy to clipboard operation
serverless-image-handler copied to clipboard

Allow user to set sharp's `animated` option

Open sskylar opened this issue 2 years ago • 3 comments

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 animated to their preference (true or false).

sskylar avatar Mar 17 '23 18:03 sskylar

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

dougtoppin avatar Mar 17 '23 20:03 dougtoppin

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

vaniyokk avatar Oct 12 '23 09:10 vaniyokk

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

simonkrol avatar Mar 19 '24 14:03 simonkrol

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.

simonkrol avatar Jun 27 '24 20:06 simonkrol