Animated gif loading in version 1.0 of p5.js

Hey All,

I was poking around in 1.0 of p5.js and saw that gif loading was supposed to be working:

So I tried looking in the source for how it worked, as I couldn’t find any documentation:



I managed to get the following code to work with an animated gif!

in preload(), just load the animated gif as an image as normal:

function preload() {
  gifFile = loadImage("../gifs/perfectBlueRedNoodleLoop.gif");

then in draw():

  for (let i = 0; i < gifFile.numFrames(); i++) {
    image(gifFile, i * 30, 0, 100, 100);

Works great! I’ll post an example working in the p5js editor when I’ve made it. Next I’m going to try to slice the frames in interesting ways. It seems there are quite a few undocumented features in 1.0, I’d be happy to help out adding documentation for it.

1 Like

Hello @jgl,

Nice work digging in the source code. I think it is already documented though: setFrame().

You are completely correct! :bowing_man:t2:‍♂

I didn’t find it because it isn’t listed here:

Rather only here:

I’ll see if I can find out how to add the reference to the p5.image methods to the main reference index!