Skip to content

Instantly share code, notes, and snippets.

@u840903
Created April 4, 2017 17:46
Show Gist options
  • Save u840903/b9459932fe850dfeedc850afb22dd700 to your computer and use it in GitHub Desktop.
Save u840903/b9459932fe850dfeedc850afb22dd700 to your computer and use it in GitHub Desktop.
const exportCanvasAsPNG = (canvasElement, fileName) => {
var MIME_TYPE = "image/png";
var imgURL = canvasElement.toDataURL(MIME_TYPE);
var dlLink = document.createElement('a');
dlLink.download = fileName;
dlLink.href = imgURL;
dlLink.dataset.downloadurl = [MIME_TYPE, dlLink.download, dlLink.href].join(':');
document.body.appendChild(dlLink);
dlLink.click();
document.body.removeChild(dlLink);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment