cms icon indicating copy to clipboard operation
cms copied to clipboard

Failure when running image transforms on animated GIFs

Open teekay opened this issue 3 years ago • 7 comments

Description

Hi there! We are having persistent issues when running image transforms on animated GIF files. These transforms all attempt to resize the images.

The issues we've seen most often are: A) the resize operation fails to complete at all B) the resize operation completes, but the resulting image is "broken" -> the animation has severe artifacts

Our stack is running on Heroku. What we see in the logs is often:

Jul 16 10:51:42 appname app/web.1 [16-Jul-2021 17:51:42] WARNING: [pool www] child 180, script '/app/web/index.php' (request: "GET /index.php?p=actions/assets/generate-transform&transformId=213") execution timed out (49.358224 sec), terminating

We've been able to confirm that we can resize the animated GIFs using ImageMagick command-line tools with no artifacts present and without any delays using this command:

$ convert input.gif  -resize 800x800 -layers OptimizeFrame output.gif

Steps to reproduce

  1. Upload the attached GIF file
  2. Associate it with some article in such a way that the image transforms are requested when viewing the article
  3. View the article and observe you don't see the image; access your system logs and observe warnings or errors

Additional info

  • Craft version: Craft Pro 3.6.17
  • Image driver: Imagick 3.5.0 (ImageMagick 6.9.10-23)
  • PHP version: 7.4.21 running on Linux 4.4.0-1093-aws in Heroku
  • Database driver & version: PostgreSQL 9.5+
  • Plugins & versions:
Amazon S3 		1.2.11
Control Panel CSS 	2.3.0
Feed Me 		4.3.6
Neo 			2.10.7
Redactor 		2.8.7
Sentry SDK 		1.1.2
SEOmatic 		3.3.44
Sprig 			1.7.0
Super Table 		2.6.8
Tags 			1.0.7
Twigpack 		1.2.15
Typed link field 	1.0.25

We've noticed similar issues that are now closed such as this one.

Please let me know if I can supply any additional information to clarify the issue. Thanks.

ocean-waves

teekay avatar Jul 16 '21 18:07 teekay

I can see that using raw Imagick locally I can generate a working thumbnail from the image provided, whereas if the image gets pushed through the image processing library that we use to abstract away image operations, it indeed runs into issues.

How big (filesize-wise) are the GIF files? Perhaps you can get away with setting transformGifs to false in your config?

andris-sevcenko avatar Jul 19 '21 08:07 andris-sevcenko

Hi @andris-sevcenko, thanks for responding.

We have issues with GIFs of any size. Sometimes they work, sometimes not. A typical GIF we might want to process would have between 1-2 MB.

Indeed we can get by with disabling transforms for GIFs. It's just not ideal in terms of serving the right image sizes to clients.

teekay avatar Jul 19 '21 13:07 teekay

I completely understand the inconvenience. I'll see if I can debug this further and see what's what.

andris-sevcenko avatar Jul 19 '21 13:07 andris-sevcenko

@teekay a bit late on the response, but I wonder if Heroku uses a policy.xml file for imagick based web requests limiting the resources imagick can use? https://imagemagick.org/script/security-policy.php

Looks like they have a way to override it with a custom one: https://help.heroku.com/RFDJQSG3/how-can-i-override-imagemagick-settings-in-a-policy-xml-file

Imagick tends to be very resource greedy by default (to the detriment of the rest of the system/dyno), so some providers put a policy in place to tame it.

angrybrad avatar Sep 30 '21 18:09 angrybrad

We have been running into this problem with gifs of any size. We have zero transforms setup. We went so far as to setup a completely vanilla install of Craft CMS 3.7.53.1 to test the gif problem. When we upload a gif, say 883kb in size to the Assets, it somehow becomes a still image of 67kb. Anyone that wants to see what we're doing, I'd be happy to setup a zoom and show.

genio avatar Aug 30 '22 20:08 genio

@genio Animated GIF transforms are only supported if you are using ImageMagick. If that’s not installed, you can disable the transformGifs config setting to prevent all GIFs from being transformed.

brandonkelly avatar Aug 31 '22 12:08 brandonkelly

@brandonkelly Maybe system should not attempt transforming gifs by default if ImageMagick is not installed?

piotrpog avatar Jan 14 '24 17:01 piotrpog