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


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.

#2 maybe


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.


It is?

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


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.


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.


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:

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

Edit: gist here


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


Considering that the creation of the gif is done in ~1 line of code, 200 lines of code is quite a complex addition :wink:
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.

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 :wink: You will be surprised at how broadly supported modern formats are by now, and how little memory webm needs for the same quality.


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… :slight_smile:


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


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


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 :stuck_out_tongue: Okay enough off-topic and apple saltiness :wink:


Doesn’t get much easier than

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 instead.