Capture HTML Canvas as gif/jpg/png/pdf?

Original answer was specific to a similar question. This has been revised:

let canvas = document.getElementById("mycanvas");
let img    = canvas.toDataURL("image/png");

with the value in IMG you can write it out as a new Image like so:

document.getElementById("existing-image-id").src = img;

or

document.write('<img src="'+img+'"/>');

Leave a Comment