When using an animated GIF with (1-2MB) you get an fatal error:
[19-Feb-2018 15:49:30 UTC] PHP Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/craft/app/vendor/pixelandtonic/imagine/lib/Imagine/Imagick/Image.php on line 242
It seems that Imagick tries to resize this animated GIF and needs a lot of RAM for this which results in some timeout.
Is this normal behavior or a bug in Craft? I tested with multiple gifs and everyone gave me problems. Is there a way to say: Animated GIFs should not get resized?
Even thought the animated GIF is only 1-2MB, there could be 1,000 frames in that GIF (they compress very well if there isn't much of a delta between frames).
So if you're trying to upload/transform an animated GIF with 1,000 frames, then PHP is essentially processing 1,000 images in that one request, so it makes sense you'd hit a 30 second timeout in that case.
On top of that, because ImageMagick is an external library that PHP has access to through Imagick, it doesn't respect any php.ini memory_limit settings and tends to use as much memory as it can grab from the system to fulfill the request.
I tested with multiple gifs and everyone gave me problems. Is there a way to say: Animated GIFs should not get resized?
If you use GD instead of Imagick, it doesn't support animated GIFs, so they turn into the first frame of the animation.
Outside of that, it might make sense to add a setting on a per transform basis for if you wanted to enable/disable GIF animations.
@angrybrad I made some fast fix by adding a image.extension != 'gif' ? doTransform : useDefaultImage and hope the frontend scales everything fine. Thanks for the answer!
Bit late but I stumbled upon this issue just now and I fixed it like this:
{% set src = image.getUrl('someImageTransform') %}
{% if image.getMimeType() == 'image/gif' %}
{% set src = image.getUrl() %}
{% endif %}
If you鈥檙e running Craft 3, there鈥檚 also this transformGifs config setting now.
I missed that config setting; thanks for the info!
Most helpful comment
If you鈥檙e running Craft 3, there鈥檚 also this transformGifs config setting now.