Using thumb() with .gif's

Hi all,

Has anyone had any success with using the thumb function with .gif’s? For me, the resulting thumbs have the file extension .gif, but only show the first frame, like a .jpg.

Thanks,

Chris

Hey Chris,

kirby’s default thumb driver uses the GD library for creating thumbnails which has no support for animated GIFs out of the box. If your want to resize them while keeping the animation frames, you can either use kirby’s built-in ImageMagick driver or if your server does not have ImageMagick installed, you have to write your own. Don’t worry, this sounds harder than it is. Just take a look at kirby/toolkit/lib/thumb.php and swap the SimpleImage class for a more powerful image manipulation library with support for animated GIFs, like this one (untested): https://github.com/coldume/imagecraft.

There is also a tutorial on building a thumbnail driver in the kirby docs:
http://getkirby.com/docs/thumbnails/building-your-own-thumb-driver

Hope, this helps!

Cheers,
Fabian

1 Like

Hey Fabian,

Using the ImageMagic library worked great for this — thanks for the tip!

Chris

1 Like

Hi Chris. Did you have to manipulate anything beyond just changing the drivers to ‘im’, for I did this but nothing seemed to have changed. My gif is still static.

Thanks,

Hey OneTimeUser,

No, I think I simply changed to ImageMagic with this line in the config:
c::set('thumbs.driver', 'im');

Largely, the change to ImageMagic did the trick but there were a few cases where, at some sizes, the GIF would not animate nicely or would show a pure black frame. Since the site owner, and not myself, is in charge of preparing the GIFs for upload, to fix the problem this week I have actually turned off the thumb function for GIFs by targeting them like this:
if($image->extension() == 'gif'):

If anyone else has had reliable GIF resizing using thumb(), I’d love to hear about it.

4 Likes

Hi Fabian,

Thanks for the guidance. I am trying to use ImageMagick on my site (http://loveandpartners.us/projects/infraculture, the last image is a test gif).

I added “c::set(‘thumbs.driver’, ‘im’);” to my config file, but my test .gif file is still static.

ImageMagick is installed on my server.

Thanks in advance for your time.

Best,
Derek

Did you set the right path to ImageMagicks executable? The corresponding option can be set using is c::set('thumbs.bin'). If thumbnails remain non-animated, you might have to change the driver according to your needs, i.e. dig into the ImageMagick documentation or ask the search engine of your choice which ImageMagick-parameters are responsible for keeping animation.

Be warned, that rresizing GIF animations can take very long. Sometimes, the resulting GIF file is even larger than your original file.

4 Likes

Thanks, Fabian.

I added c::set(‘thumbs.bin’) to my config.php file and now gif files work.

Best,
Derek

Hello!

I’m trying to use imagemagick to get my animated gifs working with thumbs but i can’t get it.

I added to my config file the next lines but nothing happens. Can anyone help please?

c::set(‘thumbs.driver’, ‘im’);
c::set(‘thumbs.bin’, ‘/Applications/MAMP/Library/bin/convert’);

Thank you!

@lenatwitteada Are new non-gif thumbs generated correctly?

Hi @texnixe i’ve reinstalled mamp pro and know it works fine! Thanks and you and sorry for bothering you.