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

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

Namely I have

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

and then


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
  • 1
    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
  • 1
    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:

% loading epstopdf package not needed, 
% as it is automatically loaded by graphicx when running pdfLaTeX
% epstopdf setup for GIF
  \noexpand\epstopdfcall{convert #1 \noexpand\OutputFile}%

\subsection*{This is a GIF version}
% The GIF file is converted to tmp-gif-converted-to.png
\subsection*{This is a jpg version}
\subsection*{This is a png version}
\subsection*{This is a pdf version}

enter image description here

EDIT: With old fashioned LaTeX, one would have to convert GIFs 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.