I have a "save" button and I need it to allow the user to download the canvas image as a PNG or JPG file.
At the moment, I found this code:
$('#save').on("click",function(){
var w=window.open('about:blank','image from canvas');
w.document.write("<img src='"+canvas.toDataURL("image/png")+"' alt='from canvas'/>");
})
Which opens the canvas image into a new page, and allows the image to be downloaded (It shows the image as a black image otherwise). Is there a way in which when the user clicks the save button they download the image directly without clearing the current canvas or opening in a new page?