I’m trying to create an animated gif to display within an image created with createImage () but it apparently doesn’t work with the great new gif update made for p5.js? Is this possible? Or am I forgetting something?
let img, gif;
function preload() {
gif = loadImage('assets/test.gif');
}
function setup() {
createCanvas(960, 540);
img = createImage(320, 180);
}
function draw() {
img.image(gif,0,0);
}
1 Like
I have even been able to verify that you cannot mask an animated gif with the mask () function either;
https://p5js.org/reference/#/p5.Image/mask
1 Like
Perhaps look at:
Also, you could try rendering your current gif state on a Graphics each frame and then masking that (untested)
https://p5js.org/reference/#/p5.Graphics
Hi! Animated gif has his own P5.js implementation already. But there are many details to polish…
If you want to dig into what it currently can / cannot do:
processing:master
← stalgiag:gifSupport
opened 02:38AM - 14 May 19 UTC
Looks like it draws the gif frame to the drawing context…?
p5.Image.prototype._animateGif = function(pInst) {
const props = this.gifProperties;
if (props.playing) {
props.timeDisplayed += pInst.deltaTime;
const curDelay = props.frames[props.displayIndex].delay;
if (props.timeDisplayed >= curDelay) {
//GIF is bound to 'realtime' so can skip frames
const skips = Math.floor(props.timeDisplayed / curDelay);
props.timeDisplayed = 0;
props.displayIndex += skips;
props.loopCount = Math.floor(props.displayIndex / props.numFrames);
if (props.loopLimit !== null && props.loopCount >= props.loopLimit) {
props.playing = false;
} else {
const ind = props.displayIndex % props.numFrames;
this.drawingContext.putImageData(props.frames[ind].image, 0, 0);
props.displayIndex = ind;
this.setModified(true);
}
}
This file has been truncated. show original
So if you want to mask, draw frame to Graphics and then mask it should work (untested).