Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick - is it possible to create a static thumbnail (with only first frame) of an animated gif file?

Some users of my website want a possibility to upload gif images to their profiles. I would allow this but... Some gif files are very large - 1-2 MB and more and it's no a good idea to create galleries with 20 x 1 MB gif animations on a single page. If I create a thumbnail with ImageMagick, the thumbnail is animated as well and I get ~600 KB thumbnail from 1 MB file. It's too much and thumbnail processing takes a long time.

Is there any way how to create a static thumbnails of animated gif files so that animated file loads only when user clicks on a thumbnail?

Thanks.

like image 700
user Avatar asked May 05 '14 08:05

user


1 Answers

You can create a thumbnail from an animated gif with ImageMagick by specifying the frame that you want. In this case, I use the first frame:

$ convert 'animated.gif[0]' thumbnail.png

The thumbnail will then be a static image, which you can turn into a hyperlink which will load the full animated gif if/when clicked.

Answer adapted from Extracting frames from an animated gif | Tips & Tricks.

like image 69
savanto Avatar answered Oct 23 '22 10:10

savanto