Last active
August 30, 2023 06:15
-
-
Save kfitfk/a58b7ca2d8e2a669d6c7cc0fb5108ba6 to your computer and use it in GitHub Desktop.
Save canvas drawing to local image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function saveCanvas(canvas) { | |
var image = canvas.toDataURL('image/png').replace('image/png', 'image/octet-stream'); // here is the most important part because if you dont replace you will get a DOM 18 exception. | |
window.location.href = image; // it will save locally | |
} | |
function openInNewWindow(canvas) { | |
// works in Firefox | |
window.open(canvas.toDataURL("image/png"), '_blank'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment