# Is there a way to export an array as a gif in Julia?

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662>\
**Category:** General Usage\
**Created:** [May 11, 2017, 9:16pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662 "2017-05-11T21:16:00Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arnaldur\_Bjarnason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnaldur_bjarnason/32/1034_2.png) [@Arnaldur\_Bjarnason](https://discourse.julialang.org/u/Arnaldur_Bjarnason)\
**Post date:** [May 11, 2017, 9:16pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/1 "2017-05-11T21:16:00Z")

</div>

I have an array that can easily be reshaped to contain Colors.jl or any other type. All gif making utilities I have found are either a part of SFML.jl which is a bit overkill for me or a plotting package. I simply want to make a gif file where one of the array’s dimensions is time and the others colors, x and y.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [May 11, 2017, 9:17pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/2 "2017-05-11T21:17:19Z")

</div>

[https://github.com/shashi/Reel.jl](https://github.com/shashi/Reel.jl) maybe

---

<div class="post-metadata">

**Author:** ![Arnaldur\_Bjarnason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnaldur_bjarnason/32/1034_2.png) [@Arnaldur\_Bjarnason](https://discourse.julialang.org/u/Arnaldur_Bjarnason)\
**Post date:** [May 11, 2017, 9:23pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/3 "2017-05-11T21:23:30Z")

</div>

Although this might be adapted to do it, Reel.jl is really an extension to Gadfly.jl and maybe some other ploting libraries and that is a whole layer of complexity. I’m not looking to plot my data, just display it at a one datapoint per pixel kind of manner.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [May 11, 2017, 9:34pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/4 "2017-05-11T21:34:21Z")

</div>

> [@Arnaldur\_Bjarnason](#):
>
> Reel.jl is really an extension to Gadfly.jl

It is?

It is a sub 200 lines with almost no dependencies to export gifs. How is that “a whole layer of complexity”.

---

<div class="post-metadata">

**Author:** ![Arnaldur\_Bjarnason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnaldur_bjarnason/32/1034_2.png) [@Arnaldur\_Bjarnason](https://discourse.julialang.org/u/Arnaldur_Bjarnason)\
**Post date:** [May 11, 2017, 9:39pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/5 "2017-05-11T21:39:49Z")

</div>

I may have read the source a bit too fast, my bad. I see now that it doesn’t extend these libraries as I assumed. Will check it out, thanks for the tip and apologies for the confusion.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [May 12, 2017, 12:15am UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/6 "2017-05-12T00:15:28Z")

</div>

You can also just save each frame independently and then use ImageMagick’s `convert` program to create the gif. It’s hacky, but it’s simple and it works.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [May 12, 2017, 8:59am UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/7 "2017-05-12T08:59:34Z")

</div>

Not sure what you’re after, but this is fairly easy (if you think Cairo isn’t too much of an overkill compared with ImageMagick), e.g. to display the results of `rand(10, 10, 10)` in time:

![](https://global.discourse-cdn.com/julialang/original/3X/9/c/9c0bb9f7b5e301d9aeab076c2981b1531c8fa99d.gif)

I did grey but color shouldn’t be vastly different.

Edit: [gist here](https://gist.github.com/cormullion/273c2ed08cf289908f5bcc3340c0c654)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 12, 2017, 9:02am UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/8 "2017-05-12T09:02:44Z")

</div>

can you provide the code for this (or a link?)

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [May 12, 2017, 9:44am UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/9 "2017-05-12T09:44:34Z")

</div>

Considering that the creation of the gif is done in ~1 line of code, 200 lines of code is quite a complex addition 😉  
Without setup code it basically boils down to this call:  
`run(pipeline(`ffmpeg -y -r $fps -f image2 -i $dir/%d.$ext $f`, stdout=DevNull, stderr=DevNull))`

There is also some code for doing the same with ImageMagick, but considering my consistently bad experience with ImageMagick, I’d go for ffmpeg! In theory, this functionality should also be easy to add to [ImageMagick.jl](https://github.com/JuliaIO/ImageMagick.jl).

While at it, I would suggest not to create gifs at all but rather webm, or some other format that isn’t as outdated as gif 😉 You will be surprised at how broadly supported modern formats are by now, and how little memory webm needs for the same quality.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [May 12, 2017, 10:18am UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/10 "2017-05-12T10:18:57Z")

</div>

I don’t think Safari supports Webm yet, so you can’t see them on Macs or iOS devices. Links to YouTube videos are probably more useful for the handful of us using Apple devices… 🙂

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [May 12, 2017, 10:30am UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/11 "2017-05-12T10:30:25Z")

</div>

Wow, really Apple? By now it feels like they’re just trying to get me mad 😃

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [May 12, 2017, 10:40am UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/12 "2017-05-12T10:40:44Z")

</div>

Better not look at this website then (Firefox on the left, Safari on the right)!

![](https://global.discourse-cdn.com/julialang/original/3X/c/1/c1de68386a22808108a4c47b6b4fb926e4235fdc.png)

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [May 12, 2017, 11:06am UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/13 "2017-05-12T11:06:04Z")

</div>

I’m not surprised anymore that Apple saved up $250 billion, now that they stopped developing OpenGL, Vulkan and doesn’t support new formats in the browser 😛 Okay enough off-topic and apple saltiness 😉

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [May 12, 2017, 5:19pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-export-an-array-as-a-gif-in-julia/3662/14 "2017-05-12T17:19:32Z")

</div>

Doesn’t get much easier than

```julia
using FileIO, Colors, FixedPointNumbers
img = rand(RGB{N0f8}, 200, 200, 30);
save("/tmp/test.gif", img, fps=5)

```

If you’re on a Mac you might need to use `ImageMagick.save` instead.
