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

conversiongifgraphics

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

\includegraphics{figures/filename.gif}

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
specifed).

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

\includegraphics[0,0][18,18]{figures/filename.gif}

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 7.3.3.1)
(./test.tex{pdftex.cfg}
LaTeX2e <2001/06/01>
Babel <v3.7h> and hyphenation patterns for american, french, german, ngerman, i
talian, nohyphenation, loaded.
(/usr/share/texmf/tex/latex/base/article.cls
Document Class: article 2001/04/21 v1.4e Standard LaTeX document class
(/usr/share/texmf/tex/latex/base/size10.clo))
(/usr/share/texmf/tex/latex/tools/verbatim.sty)
(/usr/share/texmf/tex/latex/fancyhdr/fancyhdr.sty)
(/usr/share/texmf/tex/latex/graphics/graphicx.sty
(/usr/share/texmf/tex/latex/graphics/keyval.sty)
(/usr/share/texmf/tex/latex/graphics/graphics.sty
(/usr/share/texmf/tex/latex/graphics/trig.sty)
(/usr/share/texmf/tex/latex/config/graphics.cfg)
(/usr/share/texmf/tex/latex/graphics/pdftex.def)))
(/usr/share/texmf/tex/latex/base/makeidx.sty)
Writing index file test.idx
(/usr/share/texmf/tex/latex/misc/pslatex.sty)
(/usr/share/texmf/tex/latex/pdfpages/pdfpages.sty
(/usr/share/texmf/tex/latex/base/ifthen.sty)
(/usr/share/texmf/tex/latex/tools/calc.sty)
(/usr/share/texmf/tex/latex/ms/eso-pic.sty
(/usr/share/texmf/tex/latex/ms/everyshi.sty))))

LaTeX Warning: Unused global option(s):
    [8pt,english].

No file test.aux.
(/usr/share/texmf/tex/latex/psnfss/omspzccm.fd)
(/usr/share/texmf/tex/context/base/supp-pdf.tex
(/usr/share/texmf/tex/context/base/supp-mis.tex
loading : Context Support Macros / Missing
)
loading : Context Support Macros / PDF
) (/usr/share/texmf/tex/latex/psnfss/ot1ptmcm.fd)
(/usr/share/texmf/tex/latex/psnfss/omlptmcm.fd)
(/usr/share/texmf/tex/latex/psnfss/omxpsycm.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
exmf/dvips/base/8r.enc}

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

\documentclass{article}
\usepackage{graphicx}
\usepackage{epstopdf}
\epstopdfDeclareGraphicsRule
  {.gif}{png}{.png}{convert gif:\SourceFile.\SourceExt png:\OutputFile}
\AppendGraphicsExtensions{.gif}


\begin{document}

\includegraphics{test.gif}

\end{document}

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