6

I'm trying to generate a gif from a tikz picture, using tikz's external library. Ultimately, my plan is to

  • Convert a picture to gif
  • write a node style that converts the nodes' coordinates to pixel offsets in a map file
  • use them together on a web page.

If somebody has done this before, I'm glad to get a pointer.

However, I have adapted the example from the tikz documentation which uses convert in a system call. The only difference to the original example is that I don't add code to include external and that I changed the desired output format to gif:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{external}

\tikzset{
  gif export/.style={
    external/system call/.add=
    {}
    {; convert -density 300 -transparent white "\image.pdf" "\image.gif" },
    %
    /pgf/images/external info,
  }
}
\tikzexternalize
\tikzset{gif export}

\begin{document}
  \begin{tikzpicture}
    \draw (0,0) node[draw,minimum width=1in] {TestNode};
  \end{tikzpicture}
\end{document}
  • The resulting main.pdf is empty,
  • the externalization library creates an empty main-figure0.pdf and main-figure0.dpth
  • an additional file called } is created, but I don't know what I can do with it.

I have the impression that the closing } after "\image.gif" is causing problems. When I change that line to end with

"\image.gif"},

(no space between gif and }), the resulting converted file is called main-figure0.gif} and also empty.

but I have no idea how I can fix this.

0

1 Answer 1

5

First: Do not use the standalone class with the external library! Use either one or the other. Both try to do similar things in different ways and combining them just creates trouble.

Having ; in the command is not allowed to exactly forbid the thing you are doing, i.e. to execute two commands.

The develop version of standalone supports conversion to GIF using the convert class option. This should work already but this version isn't fully tested and still a little buggy (e.g. other class options are not passed to the underlying class any longer since the change to PGF keys).

In the meantime you could do it like described in the answer to my question Shell escape after PDF is finished and closed?. This is for PDFs but should be the same for GIFs.

\documentclass[border=0pt]{standalone}

\usepackage{tikz}

\ifx\conditionmacro\undefined
  \immediate\write18{%
    pdflatex --jobname='\jobname' '\gdef\string\conditionmacro{1}\string\input\space\jobname'
  }%
  \immediate\write18{%
    convert -density 300 -transparent white '\jobname.pdf' '\jobname.gif'
  }%
   \expandafter\stop
\fi


\begin{document}
  \begin{tikzpicture}
    \draw (0,0) node[draw,minimum width=1in] {TestNode};
  \end{tikzpicture}
\end{document}

Run with pdflatex -shell-escape <file>.

The trick here is that the document calls pdflatex again in the preamble (before the PDF is created or overwritten), compiles itself (!) in this sub-call and then starts the convert command after the document was build. Afterwards it stops the main compiler run (\stop) which doesn't have to do anything in addition.

5
  • Thank you, using the article class works. My picture is now externalized. However, the tikz documentation says: "The File generation is modified by appending the ImageMagick command to system call (separated by ; as usual on Linux)". Your alternative to the externalization library also works, thank you!
    – Christoph
    Jul 20, 2011 at 13:10
  • @Christoph: I have to check the external manual again, but I'm pretty sure that I saw some comment in the TEXMF configuration file that states that ; or & etc. are not allowed. But I could be wrong. (I edited the } to ; in your comment for you.) Jul 20, 2011 at 13:24
  • Can you suggest a good place to show people the result (gif image map)? I think it's going to be quite cool...
    – Christoph
    Jul 20, 2011 at 14:40
  • @Chistoph: imgur.com allows GIFs included animated onces. Jul 20, 2011 at 14:53
  • I was thinking about the code, together with the result, but wrote a different thing. Sorry for that! I do have own webspace, but I'm sure that there's a better place where people can actually find it.
    – Christoph
    Jul 20, 2011 at 14:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .