4

I wrote a pdf animation with the animate package using transparencies.

construction-ove

To be able to show this gif, on S.E, I created not transparencies but images and I could convert it into gif with imagemagick in this way:

convert -delay 10 -loop 0 -background white -alpha remove thepdf.pdf result.gif

But I wrote it with transparencies in the animateinline environment of the animate package and the pdf file is animated.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{animate}

% creation of the ove.txt timeline file
\newwrite\Fichier 
\immediate\openout\Fichier=ove.txt
\foreach \n in {0,1,...,6}{
\immediate\write\Fichier{::\n x0}
}

\immediate\closeout\Fichier% always close the file

\newcommand{\Debut}{% Systematic start of drawing
\begin{tikzpicture}
\useasboundingbox (-2.5,-2.5) rectangle (4,2.5);}
\newcommand{\Fin}{\end{tikzpicture} }% Systematic end of drawing
\begin{document}
\begin{animateinline}[autoplay,begin={\Debut},end={\Fin},timeline=ove.txt]{1.5}
    % perpendicular straight - transparent 0
    \draw[thick] (-2.5,0)--(4,0);
    \draw[thick] (0,-2.5)--(0,2.5);
\newframe% circle - transparent 1
    \draw[thick] (0,0) circle (2cm);
\newframe%  half-line 1 - transparent 2
    \draw[thick] (0,-2)--(3,1);
\newframe%  half-line 2 - transparent 3
    \draw[thick] (0,2)--(3,-1);
\newframe%  arc 1 - transparent 4
    \draw[thick](0,2)arc[start angle=90,end angle=45,radius=4cm];
\newframe%  arc 2 - transparent 5
    \draw[thick](0,-2)arc[start angle=-90,end angle=-45,radius=4cm];
\newframe%  arc 3 - transparent 6
    \draw[thick]([xshift=2cm]45:1.171573cm)arc[start angle=45,end angle=-45,radius=1.171573cm];             
\end{animateinline}

\end{document}

I tried to convert these animated pdf into a gif and I didn't succeed.

Is it possible to convert an animated pdf file created with transparencies in this way to gif? If so, how?

  • Do I understand the questions correctly: you want the .gif without the white background? – user36296 Aug 8 '18 at 18:36
  • @samcarter with or without background, whatever, I just want to easily convert to gif without having to completely rewrite the animation with a succession of images. – AndréC Aug 8 '18 at 18:40
  • 1
    Have a look at this answer: tex.stackexchange.com/a/420405/36296 – user36296 Aug 8 '18 at 18:45
  • @samcarter That's a good lead. I see this looks possible, the animateinline environment has been modified, but I don't know how or why (I don't understand this code). – AndréC Aug 8 '18 at 18:54
  • I left a comment below the ship answer. I hope @AlexG is able to take a look at your question. – user36296 Aug 8 '18 at 19:02
4

As of animate version [2018/08/22], producing multipage output from animation frames is easily done by setting export as a class option to standalone or as a package option to animate. Use the conversion program of your choice (e. g. convert) to make an animated GIF from the PDF output.

This also works for animations that make use of package animate's timeline feature (as requested by the OP):

construction-ove

\documentclass[export]{standalone}
\usepackage{tikz}
\usepackage{animate}

% creation of the ove.txt timeline file
\newwrite\Fichier 
\immediate\openout\Fichier=ove.txt
\foreach \n in {0,1,...,6}{
\immediate\write\Fichier{::\n x0}
}

\immediate\closeout\Fichier% always close the file

\newcommand{\Debut}{% Systematic start of drawing
\begin{tikzpicture}
\useasboundingbox (-2.5,-2.5) rectangle (4,2.5);}
\newcommand{\Fin}{\end{tikzpicture} }% Systematic end of drawing
\begin{document}
\begin{animateinline}[autoplay,begin={\Debut},end={\Fin},timeline=ove.txt]{1.5}
    % perpendicular straight - transparent 0
    \draw[thick] (-2.5,0)--(4,0);
    \draw[thick] (0,-2.5)--(0,2.5);
\newframe% circle - transparent 1
    \draw[thick] (0,0) circle (2cm);
\newframe%  half-line 1 - transparent 2
    \draw[thick] (0,-2)--(3,1);
\newframe%  half-line 2 - transparent 3
    \draw[thick] (0,2)--(3,-1);
\newframe%  arc 1 - transparent 4
    \draw[thick](0,2)arc[start angle=90,end angle=45,radius=4cm];
\newframe%  arc 2 - transparent 5
    \draw[thick](0,-2)arc[start angle=-90,end angle=-45,radius=4cm];
\newframe%  arc 3 - transparent 6
    \draw[thick]([xshift=2cm]45:1.171573cm)arc[start angle=45,end angle=-45,radius=1.171573cm];             
\end{animateinline}

\end{document}
  • 1
    It works perfectly, thank you so much for this wonderful update! – AndréC Aug 24 '18 at 10:06
  • 2
    @AlexG Fantastic! I knew you can answer this! – user36296 Aug 24 '18 at 10:16
  • 2
    This is brilliant! – Max Aug 24 '18 at 11:09
  • 1
    @AndréC One downside: Speed changes that may have been defined in the timeline file are not taken into account. These must be newly defined in the GIF making step. – AlexG Aug 24 '18 at 11:28
  • This is not a problem, speed changes can be created with ImageMagick when creating the gif. The key is to be able to easily create a gif without having to rewrite the code yourself. Bravo! – AndréC Aug 24 '18 at 11:31
4

An alternative of @samcarters elegant proposal is based on @samcarter's nice answer. It is fairly easy to produce animated gifs from beamer animations. In this case you only have to replace \newframe by \pause. Unfortunately, I could not make crop work with an animated frame (without \pause it works), so I had to mess around with dimensions. It would be great if some beamer expert could fix that, I would be more than happy to remove that proposal then, especially if that beamer expert is the one mentioned above. ;-) UPDATE: I found this very nice answer whose votes I just doubled, which uses tricks of this great answer. No more cropping by hand!

\documentclass[beamer,tikz,preview,multi]{standalone}                                                                    
\let\myshipout\shipout
\begin{document}      
\let\shipout\myshipout

\begin{standaloneframe}                                                                                                  
\begin{tikzpicture}
\useasboundingbox (-2.5,-2.5) rectangle (4,2.5);
    % perpendicular straight - transparent 0
    \draw[thick] (-2.5,0)--(4,0);
    \draw[thick] (0,-2.5)--(0,2.5);
\pause% circle - transparent 1
    \draw[thick] (0,0) circle (2cm);
\pause%  half-line 1 - transparent 2
    \draw[thick] (0,-2)--(3,1);
\pause%  half-line 2 - transparent 3
    \draw[thick] (0,2)--(3,-1);
\pause%  arc 1 - transparent 4
    \draw[thick](0,2)arc[start angle=90,end angle=45,radius=4cm];
\pause%  arc 2 - transparent 5
    \draw[thick](0,-2)arc[start angle=-90,end angle=-45,radius=4cm];
\pause%  arc 3 - transparent 6
    \draw[thick]([xshift=2cm]45:1.171573cm)arc[start angle=45,end angle=-45,radius=1.171573cm];             
\end{tikzpicture}                                                                                              
\end{standaloneframe}                                                                                                    
\end{document}

enter image description here

And here is why I think this is an interesting possibility. For beamer there exist a number of tools that can help one with animations, IMHO the most notable example is given by aobs-styles. Here is an example based on the post that has lead to that super useful library.

\documentclass[beamer,tikz,preview,multi]{standalone} 
\tikzset{semivisible on/.style={alt={#1{opacity=0.5,text opacity=0.5}{}}}}
\usetikzlibrary{overlay-beamer-styles} 
\usetikzlibrary{mindmap}                                                                  
\let\myshipout\shipout
\begin{document}      
\let\shipout\myshipout

\begin{standaloneframe}  
% example based on https://tex.stackexchange.com/a/55849/121799                                                                                                
\begin{tikzpicture}[mindmap, concept color=gray!50, font=\sffamily, text=white]

  \tikzset{level 1 concept/.append style={font=\sf, sibling angle=90,level
  distance = 30mm}}
  \node[concept,scale=0.7] {beings}
    [clockwise from=135]
        child[concept color=red, visible on=<1>,semivisible on=<{4,2}>]{
        node[concept,scale=0.7]{ducks} } 
        child[concept color=blue, visible on=<2>,semivisible on=<{1,3}>]{
        node[concept,scale=0.7]{marmots} } 
        child[concept color=orange, visible on=<3>,semivisible on=<{2,4}>]{
        node[concept,scale=0.7]{koala bears} } 
        child[concept color=green!50!black, visible on=<4>,semivisible on=<{3,1}>]{
        node[concept,scale=0.7]{squirrels} };
\end{tikzpicture}
\end{standaloneframe}                                                                                                    
\end{document}

enter image description here

  • 1
    A very ingenious idea, thank you very much :) – AndréC Aug 8 '18 at 19:39
  • You said "It is fairly easy to produce animated gifs from beamer animations." Can you explain that right here or would you prefer that I ask a new question about it? – AndréC Aug 10 '18 at 5:48
  • 1
    @AndréC I am only using your conversion chain convert -delay 10 -loop 0 -background white -alpha remove thepdf.pdf result.gif (modulo some -density and a different value for delay). That is, if you run one of these snippets and then run that convert command, you have an animated gif. If you want a transparent background, you may need these conversion chains. – marmot Aug 10 '18 at 5:52

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.