var canvas = document.getElementById("mcanvas");
image = canvas.toDataURL("image/png", 1.0).replace("image/png", "image/octet-stream");
var link = document.createElement('a');
link.download = "my-image.png";
link.href = image;
link.click();
//download canvas as image
function downloadCanvas() {
let link = document.createElement("a");
link.download = "image_name.png";
link.href = canvas.toDataURL("image/png");
link.click();
}