# Inline conversion of graphics

I'm using luatatex 1.0.4 on Linux.

I read several articles about directly converting image files within the LaTeX process. But somehow I fail to use it properly for converting gif-files on the fly. I have the following folder structure:

+   main folder
main.tex
|
-+ image folder
abc.tex
MySample.gif


the abc.tex contains simply

\includegraphics[width=0.5\textwidth]{./images/MySample.gif}


and the main.tex has

\documentclass[a4paper,11pt]{article}
\usepackage{arabluatex} % for support of arabic fonts
\usepackage{epstopdf}
%\DeclareGraphicsExtensions{.gif, .ps, .eps, .png}
\epstopdfDeclareGraphicsRule{.tif}{png}{.png}{%
convert #1 \OutputFile
}
%\epstopdfDeclareGraphicsRule{.gif}{png}{.png}{convert #1 dirname #1/basename #1 .gif-gif-converted-to.png}
%\epstopdfDeclareGraphicsRule{.gif}{png}{.png}{mogrify -format png}
%\epstopdfDeclareGraphicsRule{.gif}{png}{.png}{convert #1 basename #1 .gif-gif-converted-to.png}
%\epstopdfDeclareGraphicsRule{.gif}{png}{.png}{convert #1 -set filename:base "\%[basename]" "\%[filename:base]-gif-converted-to.png"}
\AppendGraphicsExtensions{.gif}

\begin{document}
Include gif-Image
\input{./images/abc}
\end{document}


If I comment the package arabluatex than I cannot compile cause Undefined control sequence. \epstopdfDeclareGraphicsRule. If I leave it on the log-file says:

(./images/abc.tex
Package epstopdf Info: Source file: <./images/MySample.gif>
(epstopdf)                    date: 2019-01-21 14:32:08
(epstopdf)                    size: 835 bytes
(epstopdf)             Output file: <./images/MySample-gif-converted-to.png>
(epstopdf)             Command: <convert ./images/MySample.gif dirname ./image
s/MySample.gif/basename ./images/MySample.gif .gif-gif-converted-to.png>
(epstopdf)             \includegraphics on input line 3.
system(convert ./images/MySample.gif dirname ./images/MySample.gif/basename
./images/MySample.gif .gif-gif-converted-to.png) executed.
Package epstopdf Info: Result file: <./images/MySample-gif-converted-to.png>.

! Package luatex.def Error: File ./images/MySample-gif-converted-to.png' not f
ound.


From the logs I would conclude the conversion is done. I tried the different commented approaches but none of them succeeded.

• Under Linux, why not install Image Magick or the fork Graphics Magick and convert all GIFs to PNGs in the command line manually? It is actually easier, except if your GIFs change a lot. – Martin Scharrer Jan 22 at 8:24
• convert #1 dirname #1/basename #1 .gif-gif-converted-to.png looks wrong, the  should at least be before the .gif or the space should be gone. – Martin Scharrer Jan 22 at 8:26
• Try first without some complicated directory structure. – Ulrike Fischer Jan 22 at 8:44
• The reason for inlining it is that the conversion is done automatically. Therefore the command line is nice but not usable for my scenario. Honestly I do not understand how to write it properly, e.g. convert #1 dirname #1/basename #1.-gif-converted-to.png does not help neither :-( I do not get any kind of converted pics neither in the folder nor in its sub. – LeO Jan 22 at 8:45
• you need to use --shell-escape which is a security risk unless you have full knowledge of all the tex code, and you convert the file every time which is slow, why not simply run convert before running tex? The eps to pdf conversion is different as it is allowed to run without --shell-escape using a restricted version of ghostscript running in safe mode – David Carlisle Jan 22 at 10:55

You can use the same graphics rule you already use for .tif, so

\documentclass[a4paper,11pt]{article}
\usepackage{graphicx}
\usepackage{epstopdf}
\epstopdfDeclareGraphicsRule{.gif}{png}{.png}{%
convert #1 \OutputFile
}
\AppendGraphicsExtensions{.gif}

\begin{document}
Include gif-Image
\input{./images/MySample}
\end{document}


works fine. The epstopdf package does not rely on LuaTeX, it works with pdfTeX too because it is based on shell commands. To allow TeX to execute arbitrary shell commands like convert, you have to compile the document with shell-escape enabled, so run

lualatex -shell-escape main


lualatex main

• Thx for this hint (shell-escape) cause I didn't find it properly. This saved my day :-) – LeO Jan 22 at 10:24