Created
May 8, 2025 13:28
-
-
Save patricker/e70ae4114d94e2e595406d70cc941e32 to your computer and use it in GitHub Desktop.
This script exports a canvas as a png for easier printing
This file contains hidden or 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 exportCanvasAsPNG(id, fileName) { | |
var canvasElement = document.getElementById(id); | |
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); | |
} | |
exportCanvasAsPNG('appCanvas', 'music_sheet.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment