JS HTML

HOW TO DOWNLOAD CANVAS AS IMAGE IN JAVASCRIPT

DUMMY CANVAS

01

JUST AN EMPTY CANVAS <canvas id="demo" width="200" height="200"></canvas>

DRAW BLACK SQUARE let ctx = document.getElementById ("demo").getContext("2d"); ctx.fillRect(50, 50, 100, 100);

DOWNLOAD CANVAS

02

GET CANVAS let can = document.getElementById("demo");

CREATE LINK let anc = document.createElement("a"); anc.download = "IMG.PNG"; anc.href = can.toDataURL("image/png");

"FORCE DOWNLOAD" anc.click(); anc.remove();