Created
April 4, 2017 17:46
-
-
Save u840903/b9459932fe850dfeedc850afb22dd700 to your computer and use it in GitHub Desktop.
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
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