Is there any way to include an animated GIF directly in either PDFLaTeX or XeLaTeX? I realize the animate
package can include animations in a PDF, but it doesn't support animated GIFs and you have to split them up manually into EPS or PNG files as far as I can tell.
-
2What is the problem with splitting the gif first? The manual part of the job is to enter something like `convert my.gif my.png' at the command line.– AlexGNov 15, 2010 at 12:34
-
15It's a pain in the butt!– ptomatoNov 15, 2010 at 12:36
-
If you have imagemagick installed on your computer you could rename its convert.exe binary into im-convert.exe. This prevents the system convert.exe program from being run. Other solutions on savage.net.au/ImageMagick/html/install-convert.html#Solutions– AlexGNov 15, 2010 at 13:00
2 Answers
Yes, use the movie15 package (in Latex), which supports GIFs directly. You will need to use a PDF viewer that has the right plugin to supported GIF animations.
Note on media9
The movie15 package has been marked deprecated on CTAN for some time in favour of the media9 package, because media9 uses the better supported approach to embedding media of Adobe's Rich Media Annotations, rather than the old, ad-hoc, plug-in based approach of movie15. This has the consequence that building rich media documents in media9 is a more flexible process, supporting several workflows, and the results typically can be displayed with more viewers. However, media9 does not support animated GIFs - the GIFs would have to be converted to a supported format such as FLV or MP4 before embedding.
-
48What – I can't get animations on paper? They do have that in the Harry Potter movies. Why can't we? Nov 15, 2010 at 10:57
-
13@Harald: yes, paper is a sort of PDF viewer, but it's hard to find paper that supports animated content. I've had no personal experience with magic paper. I'd love to hear of other people's... Nov 15, 2010 at 11:18
-
9@Charles: Oh, it's been around for a while. Remember the old comics when you need to flip quickly through the pages to see an animation effect? Now, I'm sure some journals would object heavily to my 1200+ page manuscript containing 60s of video @ 24 fps.. Nov 15, 2010 at 13:34
-
9@Martin: You are quite right! Someone must write a printer driver that creates flip books when given an animated GIF. Nov 16, 2010 at 10:19
-
2
For animated GIF, package animate
should be used. Animated GIF sequences tend to be short and don't justify a video embedding package, such as media9
, that embeds a videoplayer component alongside the sequence and which requires the GIF to be transcoded into MP4 first.
animate
is a lightweight alternative with the bonus of producing embedded animations that work in AR versions for Win, OSX and Linux, while media9
embedded video only works in AR for Win and OSX. For use with animate
, the GIF must be split into a PNG or JPEG sequence, optimized GIF must be un-optimized first:
These are the steps for a 100 frames animated GIF, using package animate
and playing at 12 frames per second:
gifsicle --unoptimize animated.gif | convert - frame-%d.png
\animategraphics[loop,autoplay]{12}{frame-}{0}{99}
With the deprecated movie15
package it was, at least theoretically, possible to embed animated GIF without preprocessing. This method depended on the availability of a third-party plugin, some QickTime component to be specific, used by AR for displaying the GIF. This never worked reliably, though.
-
1@CharlesStewart. This uses a QuickTime sub-plugin. I never got it reliably working.– AlexGJan 14, 2014 at 7:08
-
1Unfortunately this solution depends on JavaScript support, so it won't work on Evince and Okular. Mar 24, 2015 at 18:17
-
4@MateusAraújo Exactly. Somebody should take the challenge and add some opensource JS Engine, such as JavaScriptCore from webkit (used by many popular web browsers, btw), to opensource PDF viewers.– AlexGMar 25, 2015 at 7:47
-
2+1 I was using
convert
to extract the frames, but they looked horrible when including them in the tex document. Usinggifsicle
saved my day! Feb 25, 2016 at 10:07 -
2@ben Cannot comment on your post without seeing your example and the image files. Usually, compiling time is not an issue. As viewers, acrobat reader, foxit and pdfxchange can be used.– AlexGJan 22, 2018 at 21:36