Skip to content

Instantly share code, notes, and snippets.

@kfitfk
Last active August 30, 2023 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kfitfk/a58b7ca2d8e2a669d6c7cc0fb5108ba6 to your computer and use it in GitHub Desktop.
Save kfitfk/a58b7ca2d8e2a669d6c7cc0fb5108ba6 to your computer and use it in GitHub Desktop.
Save canvas drawing to local image
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