# Manipulate to GIF

I am using the following example code to export Manipulate to GIF:

ManToGif[man_, name_String, step_Integer] :=
Export[name <> ".gif",
Import[Export["f:\\test.avi", man], "ImageList"][[1 ;; -1 ;; step]]]

man = Manipulate[Plot[Sin[x], {x, 0, end}], {end, Pi, 2 Pi, 0.1}];

ManToGif[man, "f:\\test", 1];


Is there another possibility to do that? How can I see the value of the variable end?

You see at bottom of the movie some strange black bars and also at the right edge a black vertical line, which should not be there.

• Why don't you press that + toggler to open the additional control bar? It includes InputField which shows how the value updates. – e.doroskevic Aug 11 '16 at 12:55
• Or, programmatically, {end, Pi, 2 Pi, 0.1, Appearance -> "Open"}. – Kuba Aug 11 '16 at 12:56
• Those are not "strange black bars", those are the background. If you want to avoid showing the background you need to control the size of the plot so that it covers the same area at all time. – C. E. Aug 11 '16 at 12:59
• closely related: How to Export this animation as a gif file – Kuba Aug 11 '16 at 13:01
• @mrz - I still got a bit of movement in the axes until I added the option ImagePadding -> 10, now I get this. Another option would be to give ImageSize two numbers, so that the width and height are always specified. – Jason B. Aug 11 '16 at 14:16

You can do this outside of the manipulate box and show the variable's value as a legend. Also by using fixed image sizes and aspect ratios you can minimize the occurrence of black bars as the variables change.

First Step: Make a table of your desired Plots, I think the code here is relatively easy to understand:

Anim = Table[
Plot[Sin[x], {x, 0, t}, PlotRangePadding -> 0.1, ImageSize -> 500,
AspectRatio -> 1/2, PlotLegends -> TextString@Row@{"T=", t}]
, {t, Pi, 2 Pi, .1}
];


Second Step: Export it as a GIF image :)

Export["anim.gif", Anim]


Final Result:

Hope it's suitable for what you have in mind ;)

UPDATE

If you want it to move forward an then backward you can make tables of the animation for each direction and join them:

Anim1 = Table[
Plot[Sin[x], {x, 0, t}, PlotRangePadding -> 0.1, ImageSize -> 500,
AspectRatio -> 1/2, PlotLegends -> TextString@Row@{"T=", t}]
, {t, Pi, 2 Pi, .1}
];

Anim2 = Table[
Plot[Sin[x], {x, 0, t}, PlotRangePadding -> 0.1, ImageSize -> 500,
AspectRatio -> 1/2, PlotLegends -> TextString@Row@{"T=", t}]
, {t, 2 Pi, Pi, -.1}
];

Anim = Join[Anim1, Anim2];


UPDATE 2

If you want to do this with the manipulation box just add a two-dimensional picture size to your plot like this:

man = Manipulate[
Plot[Sin[x], {x, 0, end},
ImageSize -> {500, 250}], {end, Pi, 2 Pi, 0.1,
Appearance -> "Open"}, ContentSize -> 550]


Or this one (without fixing the plot range):

man = Manipulate[
Plot[Sin[x], {x, 0, end}, ImageSize -> {500, 250}], {end, Pi, 2 Pi,
0.1, Appearance -> "Open"}, ContentSize -> 550]


• I think you can still use manipulate and get good results if you use the fixed formatting there – Siav Josep Aug 11 '16 at 15:02
• Thank you for your help ... this I did already, but I wanted to see the whole window of the Manipulate function - therefore my question. – mrz Aug 11 '16 at 15:34
• would it be possible to get a complete example, with the exporting, the inclusion of the manipulate UI, and the alternating between forwards and backwards? I'm not super Mathematica savvy yet so it's taking me a while to figure out how to string to it together. basically my whole interest in Mathematica is being able to type in 3-D equations and get exactly this behavior – Joseph Garvin Jan 13 at 19:51
• @JosephGarvin can you give an example of the 3D equation that you're interested in? – Siav Josep Feb 14 at 16:04
• @SiavJosep: something like $z=\frac{ax}{ax+by}$ with sliders for $a$ and $b$. – Joseph Garvin Feb 20 at 5:07

Another solution:

ManToGif[man_, name_String, step_Integer] :=
Export[name <> ".gif",
Import[Export[FileNameJoin[{NotebookDirectory[], "test.avi"}], man],
"ImageList"][[1 ;; -1 ;; step]]];

man2 = Manipulate[Plot[Sin[x], {x, 0, end}, PlotRange -> {{0, 2 Pi}, {-1, 1}}]
, {end, 0, 2 Pi, 0.1}];

ManToGif[man2, FileNameJoin[{NotebookDirectory[], "test"}], 1];


This creates an AVI and corresponding GIF animation:

• For the original ManToGif, see this answer by Vitaly and its link to his community post. (The original is essentially the same as this, but with a fix for MacOS.) – Michael E2 Mar 15 '17 at 11:08