[Tex/LaTex] Convert GIF image to PNG on the fly


I am using pdflatex on Linux and attempting to convert GIF to PNG.
I can run scripts to find out the image attributes and even and convert
the files supplied from a folder but I can not write back to that
folder (or I'd convert them by hand). I have hundreds of gif files.

I have found great instructions with regard to converting GIF to EPS. Those
weren't working for me, so I thought I'd try PNG files because I normally
use PNG files. Thanks in advance for your time for reading and any comments.

Before \begin{document}, I have defined:

\DeclareGraphicsExtensions{.gif, .ps, .eps, .png}
\DeclareGraphicsRule{.gif}{png}{}{`convert #1 'png:-'}

Inside my document, I have


When I run pdflatex on my document, I get an error:

! LaTeX Error: Cannot determine size
of graphic in `convert
figures/filename.gif 'png:-' (no size

So, I added a bounding box manually to the includegraphics command:


I got the dimensions using imagemagick's identify command.

I am able to convert the file, write it to a new file, and view it using imagemagick:

$ convert figures/filename.gif gif:figures/filename.png

I believe that the "convert" command I specified in the graphics rule is not actually running. What am I doing wrong?

Here are some details about my build:

$ pdflatex test.tex
This is pdfTeX, Version 3.14159-14h-released-20010417 (Web2C
LaTeX2e <2001/06/01>
Babel <v3.7h> and hyphenation patterns for american, french, german, ngerman, i
talian, nohyphenation, loaded.
Document Class: article 2001/04/21 v1.4e Standard LaTeX document class
Writing index file test.idx

LaTeX Warning: Unused global option(s):

No file test.aux.
loading : Context Support Macros / Missing
loading : Context Support Macros / PDF
) (/usr/share/texmf/tex/latex/psnfss/ot1ptmcm.fd)
<use `convert figures/remconf_edit.gif 'png:-'> [1{/usr/share/texmf/dvips/confi
g/pdftex.map}] (/usr/share/texmf/tex/latex/psnfss/omsphv.fd) [2] [3] [4]
(./test.aux) )</usr/share/texmf/fonts/type1/bluesky/cm/cmsy10.pfb>{/usr/share/t

Best Answer

You need to enable shell escapes. With MiKTeX you do -enable-write18 and with TeXlive -shell-escape.

You can set up different conversion rules with the epstopdf package

  {.gif}{png}{.png}{convert gif:\SourceFile.\SourceExt png:\OutputFile}




Using epstopdf you can control if the conversion should be done every time you compile or only if the target file is missing.