# Insert GIF in LaTeX

I'd like to insert a GIF image in my text and I found this Convert GIF image to PNG on the fly.

So I pasted in my document

\documentclass[a4paper]{article}
\usepackage{graphicx}
\DeclareGraphicsRule{.JPG}{eps}{.JPG}{convert #1 eps:-}
\begin{document}
\framebox{\includegraphics[0,0][150,200]{DSC00121-SMALL.JPG}}
\end{document}


Namely I have

\usepackage{graphicx}
\DeclareGraphicsRule{.JPG}{eps}{.JPG}{convert #1 eps:-}


and then

 \framebox{\includegraphics[0,0][150,200]{nn.JPG}}


Also I have renamed the picture as nn.JPG

But it doesn't work! Any help?

• Includegraphics command has a single optional argument (in [ ] ), with possibly several comma separated key=value pairs. Hence your syntax is wrong. For a bitmap you could have to provide the bunding box, but for an eps (even if created on the fly) it is read from the file. Try \includegraphics[width=0.5\textwidth]{small.gif} . – Jhor Feb 21 '19 at 8:51
• By the way I assume that you have defined the graphicsrule for gif and not only for jpg. Of course renaming .gif to .jpg can not work, as their format is quite different. – Jhor Feb 21 '19 at 8:54
• @Jhor Thanks for answering! I tried \includegraphics[width=0.5\textwidth]{small.gif} but it doesn't work either. It says "unknown graphics extention .gif" – Γιάννης Παπαβασιλείου Feb 21 '19 at 8:57
• @Jhor I have renamed the picture small.gif – Γιάννης Παπαβασιλείου Feb 21 '19 at 8:59
• Which motor are you using (LaTeX, pdfLaTeX, XeTeX ??) – Jhor Feb 21 '19 at 9:06

Here is the MWE for pdfLaTeX, assuming that you have the command line convert from image magic installed, and using the .png route, as pdfLaTeX already has the method for PNG:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
% as it is automatically loaded by graphicx when running pdfLaTeX
%\usepackage{epstopdf}
% epstopdf setup for GIF
\DeclareGraphicsRule{.gif}{png}{.png}{%
\noexpand\epstopdfcall{convert #1 \noexpand\OutputFile}%
}
\AppendGraphicsExtensions{.gif}

\begin{document}
\subsection*{This is a GIF version}
\includegraphics[width=0.5\linewidth]{tmp.gif}
% The GIF file is converted to tmp-gif-converted-to.png
\subsection*{This is a jpg version}
\includegraphics[width=0.5\linewidth]{tmp.jpg}
\subsection*{This is a png version}
\includegraphics[width=0.5\linewidth]{tmp.png}
\includegraphics[width=0.5\linewidth]{tmp}
\end{document}


EDIT: With old fashioned LaTeX, one would have to convert GIGs to EPS. For this purpose, one can replace the \DeclareGraphicsRule above by the following one:

\DeclareGraphicsRule{.gif}{eps}{.gif.bb}{convert #1 eps:-}


Then the conversion command is written verbatim in the .dvi file, and executed by dvips provided it is run with the -R0 option. Finally the PDF file can be produced by using ps2pdf.

However, this method has several drawbacks:

• the converted figures are huge;
• it does not work with dvipdfm(x).
• it works only if the .gif.bb file has been created, that can be done with a command like:

identify tmp.gif |sed -r -e "s/(.*)\s+([0-9]{2,})x([0-9]{2,})\s+(.*)/%%BoundingBox: 0 0 \2 \3/" > tmp.gif.bb

for each graphic file tmp.gif.

In this context, it becomes much more efficient to write a batch to perform the conversion of all the files outside of LaTeX/dvips, by using convert with suitable options, or Netpbm, or Irfanview` (windows only) and so on.