Message Boards Message Boards

14
|
23160 Views
|
4 Replies
|
25 Total Likes
View groups...
Share
Share this post:

How to export GIFs

Posted 11 years ago
Hello everyone!
I thought I'd share a quick tutorial for exporting GIFs in Mathematica, since I get asked that a lot, and I think it's a great way of sharing interesting visualisations with a large audience on the web.
First define a function frame:
frame[t_] :=
Show[
Graphics[{Circle[{-1, 0}, 1], PointSize[Large],
   Point[{Sin[t] - 1, Cos[t]}], Red,
   Line[{{-1, 0}, {Sin[t] - 1, Cos[t]}, {0, Cos[t]}}]}],
Plot[Cos[x + t], {x, 0, 2 Pi}, PlotRange -> {-1, 1}],
ImageSize -> 300];

Then generate a list of the frames (not including the last frame here, as frame[2 Pi] is the same as frame[0]):
frames = Table[frame[t], {t, 0, 2 Pi, (2 Pi)/50}][[;; -2]];

Now you can export this as a gif:
Export["animation.gif", frames]

POSTED BY: Matt Henderson
4 Replies

I am adding four usually requested options for .GIF, so that everything is in one post: the number of repetitions, the pause between each repetition, the animation time, and the direction of the animation.

frame[t_] := Show[
   ParametricPlot[{Sin[3 x], Sin[4 x]}, {x, 0, t}, Axes -> None, 
    PlotStyle -> Thick, PlotRange -> {{-1.05, 1.05}, {-1.05, 1.05}}, 
    ImageSize -> Large],
   Graphics[{PointSize[Large], Red, , Point[{Sin[3 t], Sin[4 t]}]}]
   ];
framesForward = Table[frame[t], {t, 10^-6, 2 \[Pi] + 10^-6, \[Pi]/50}];
framesBackward = Reverse[framesForward];
framesForwardBackward = Join[framesForward, framesBackward];

Export["Lissajous forward.gif", framesForward, 
  AnimationRepetitions -> \[Infinity], 
  "DisplayDurations" -> 
   ReplacePart[
    Table[5/Length[framesForward], Length[framesForward]], -1 -> 2.0]];

Export["Lissajous forwardbackward.gif", framesForwardBackward, 
  AnimationRepetitions -> \[Infinity], 
  "DisplayDurations" -> 
   ReplacePart[
    Table[10/Length[framesForwardBackward], 
     Length[framesForwardBackward]], {Length[framesForward] -> 
      2.0, -1 -> 2.0}]];

Lissajous forward

Lissajous forwardbackward

References

https://mathematica.stackexchange.com/questions/115851/add-delay-to-the-final-frame-of-a-gif?rq=1 https://mathematica.stackexchange.com/questions/145536/create-gif-looping-animation Mathematica's documentation for .GIF: https://reference.wolfram.com/language/ref/format/GIF.html

POSTED BY: Nam Tran
Hello, guys.
Thank you very much for the information. Examples are very complete and easy to perform.

It has long sought.
POSTED BY: marife cuauro
Hi Matt! I am a long-time fan of your blog. Last week I published some animated GIFs using the same steps as you, thank you for sharing this quick tutorial.
Vitaliy, that's great. I've just explained the inverse operation of what you did, the process of taking an animated GIF to obtain a 3D object emoticon  

Visualizing Animated GIFs Along The Time Dimension With Image3D
.


POSTED BY: Bernat Espigulé
This is very nice, Matt, thank you! I am actually too a big fan of gifs and trying to use them as much as possible. For example I just made one in this post walks on Pi. GIFs, despite some shortcomings, are still a very cheap and neat media to deliver animations. I like a lot, btw, your gif-blog and am wondering if you aware of a similar in nature blog called ARCHERY ?

Anyway, I'd just wanted to say to everyone else that GIFs are pretty cool - because they are so easily embeddable in posts! And One doesn't have to make animations only. You can convert short videos into GIFs and even represent 3D objects differently. For example, this is a 3D image of scan from a real car engine:
engine = ExampleData[{"TestImage3D", "CTengine"}]



And this is how you can swap through its layers with a GIF:
Export["test.gif", Image3DSlices[engine]]

POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract