[Tex/LaTex] Getting GIF and/or moving images into a LaTeX presentation

animationsbeamergifgraphics

I'm very new to presentations in LaTeX (I've been using PowerPoint for years but have finally converted).

I am wondering how to get a GIF into a section. If need be, I can convert a GIF into lots of pictures and have them overlay to give the impression of movement.

Best Answer

1. Convert and split animated GIF into PNG sequence

convert -coalesce something.gif something.png

or

magick convert -coalesce something.gif something.png

convert/magick convert is a command line tool from the ImageMagick.org software package. The command name depends on the software version.

This produces a set of numbered PNG files something-0.png, ..., something-16.png (Here, the original GIF http://i.stack.imgur.com/VHJmL.gif, renamed to something.gif consists of 17 frames.) Option -coalesce is necessary to undo a possible optimization of the original GIF file.

2. Get original animation speed

magick identify -verbose something.gif | grep 'Delay'

Users of Windows may want to run

magick identify -verbose something.gif | sls -Pattern 'Delay'

in the PowerShell.

This outputs lines (one for every frame) like:

Delay: 10x100
Delay: 10x100
Delay: 10x100
...

The frame rate (frames per second), to be passed as an argument to the \animategraphics command below, is found by dividing the number after x by the number in front of it:

frame rate = 100 (tics/s) / 10 (tics/frame) = 10 frames/s

3. Embed PNG sequence as an embedded looping animation in the final PDF

(This kind of animation requires a JavaScript-supporting PDF viewer, such as Acrobat Reader or KDE Okular.)

\documentclass{beamer}
\usepackage{animate}

\begin{document}
\begin{frame}{Embedded Animation}
  \animategraphics[loop,controls,width=\linewidth]{10}{something-}{0}{16}
\end{frame}
\end{document}

Argument {10} sets the desired frame rate (frames per second), {0} and {16} set the first and last file numbers of the PNG series to be included in the animation. Note that frame rates above 30 FPS, if at all achieved by the PDF viewer, do not make much sense. 30 FPS is a typical value in video encoding. Use command option measure and the + button to see which frame rates are possible. They may depend on the image size and of course on the hardware on which the PDF viewer is running.

For a more GIF-like impression, option autoplay can be used instead of or in addition to option controls.

enter image description here