Save canvas image to a variable [p5.js]

Hey, I’m trying to save a canvas image to variable, because later y want to push that variable into a an array, that at end of the loop goes to a database.

I know that:

saveCanvas(canvas, name,".png") 

downloads an image, but what I need is something like:

let img = saveCanvas(canvas, name,".png")  ; 

thumbnails.push(img) ;

is this possible?

1 Like

p5js.org/reference/#/p5/get
p5js.org/reference/#/p5.Image/save

const thumbs = [];

const img = get();
thumbs.push(img);
img.save(frameCount, '.png');
1 Like

hi, just tried that, but is not a png file :c

also, I name my canvas, so I change my to:

let currentFrame = () => {
    //c is the name of my canvas 
    const img = c.get() ;
    img.save(frameCount, '.png');
    return img ;
};