Is there a way on how to convert P5.image object into base64 png image object?
I would like to:
Note:
If I wanted to post my whole canvas (already solved) I simply grab the canvas contents with canvas.toDataURL() and use that - but since cropped result is what I need - this isnt the way.
Thank you
Oliver
something like this should work:
var img;
function setup() {
img = loadImage("cat.jpg");
}
function mousePressed() {
img.loadPixels();
console.log( img.canvas.toDataURL() );
}
Worked like a charm - thank you.
@lmccart - Lauren, a question: Do you think it would be helpful to propose and create some functions for beginners to get() the canvas encoded images - or parts of it (with get()) in case they would like to upload them somewhere per POST?
_Like lets say - upload sketches by users to a server?_
I just did it for one project and it wasn't easy for me to figure everything out.. What do you think?
Anyway big thank you :)
This is nowhere in the documentation. Thanks for this.
Most helpful comment
something like this should work: