3

Our site makes use of gifs to enable the client to upload basic animating images. Any asset field on the site can be jpg, png or gif, and the site makes significant use of transforms for responsive imagery.

Transforms for jpgs and pngs are working fine, but the gif transforms are coming out huge (significantly bigger than the original file size), and at the point of transform generation, the server is grinding almost to a halt, with most of the Generating pending image transforms tasks eventually stalling.

Image 1

  • Natural: 2.4MB
  • 400px Constrain: 4.3MB
  • 800px Constrain: 19.2MB
  • 1200px / 1600px / 2400px Constrain: Failed

Image 2

  • Natural: 5.4MB
  • None of the transforms for this seem to be being created now (I previously had to remove it because of the detrimental effect of the transform process on the server but have just tried re-uploading and visiting the page), but one of these was something like 37MB!

Technical Details:

  • Craft 2.6.2967
  • imageDriver is set to imagick (which is reported to be available under Utilities / Server Info)
  • defaultImageQuality is set to 70
  • PHP Memory Limit is set to 256MB (had previously been 512MB, which may explain why none of the transforms for Image 2 are being created any more)
  • PHP Max Execution Time is set to 90 seconds
  • What version of Imagick are you running? Any chance you can send one of the offending GIFs to support@craftcms.com? – Brad Bell Mar 29 '17 at 15:20
  • Hey @BradBell, Imagick is 3.4.1. And sure, I'll send you over Image 2 as that seems to be the more problematic of the 2. Cheers! :) – Mike Vaux Mar 29 '17 at 16:08
  • @MikeVaux Did you figure this out? – Fred Carlsen Jun 1 '17 at 8:42
  • Hi @FredCarlsen, see below for a brief write up of my discussions with Craft Support :) – Mike Vaux Jun 6 '17 at 9:44
3

No Current Good Solution

Having liaised directly with Craft Support on this issue, the outcome after a bit of research was that there is not currently any good solution.

Apparently, Imagick is really, really bad at animated GIFs, but there's no other option.

My workaround was to edit the templating for gif images, so a super-simplified version would look something like the following:

{% set src = image.getUrl('someTransform') %}

{# No transform used for gifs #}
{% if image.getMimeType() == 'image/gif' %}
    {% set src = image.getUrl() %}
{% endif %}

<img src="{{ src }}">

Whilst this did result in larger than ideal file sizes for gifs (because the original file was being used rather than smaller transforms), it prevents the issues detailed above. Not great, but better than the enormous file sizes we were seeing and the tasks getting stuck!

Possibilities in Craft 3

Apparently, Craft 3 allows for further image optimisation after transforms, and there's a plugin that capitalises on this already, so hopefully, we'll see some improvement in Craft 3.

  • 1
    I ran into pretty much the same issue. My solution was to host all gifs on giphy.com and then just paste the image urls into the cms. Thats far from perfect but this way all optimization is done on far more advanced hardware. – KSPR Jun 7 '17 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.