Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Keep gif animated after resizing


Go to End


4 Posts   1423 Views

Avatar
MarioSommereder

Community Member, 107 Posts

14 January 2015 at 4:03am

Hej there.

I'm using $Image.SetWidth(...) to resize images inside the template (various sizes for responsive design).

The problem is, that only the first frame of the animated gif comes back. Is there any setting or workaround to avoid this, so that the whole animated gif is given back?

Thanks in advance!

Cheers, Mario

Avatar
martimiz

Forum Moderator, 1391 Posts

14 January 2015 at 11:33pm

SilverStripe uses GD to resize images, and it doesn't seem to support animated gifs.

Just thinking... One thing that has come up before is that SilverStripe will resize the image, even if the original image already has the required size. I'm not 100% sure but I think that is still the case, but if so, there is a very old post here: http://www.silverstripe.org/community/forums/archive/show/1200. Note: the current function has changed somewhat., but the idea still stands. So this behaviour could be overruled by extending Image and overriding the cachedFile function...

Avatar
MarioSommereder

Community Member, 107 Posts

15 January 2015 at 1:54am

Hm, that's bad. How to make a image responsive then?

Right now, I use srcset with different images generated via $Image.SetWidth() and a Polyfill. But when animated GIFs are not supported, this solution won't work.

Anyone any ideas?

Avatar
martimiz

Forum Moderator, 1391 Posts

15 January 2015 at 3:19am

I guess you'd have to create multiple sized files up front, and skip the setWidth. At this point I just don't think you can generate resized animated GIFs on the fly out of the box...

There seems to be an imagick backend available in silverstripe, for which you need to have imagick installed. I have no experience with it, but it should be able to resize animated GIFs (http://php.net/manual/en/imagick.coalesceimages.php). Maybe someone else..?