Created
August 3, 2022 18:49
-
-
Save stekhn/b7d4628d32267396ff448fda420172cd to your computer and use it in GitHub Desktop.
Save HTML5 canvas element as PNG file
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 canvas = document.getElementsByTagName('canvas')[0]; | |
const dataURL = canvas.toDataURL('image/png'); | |
const timestamp = Math.floor(Date.now() / 1000).toString(36).slice(2); | |
const link = document.createElement('a'); | |
link.download = `download-${timestamp}.png`; | |
link.href = dataURL; | |
link.click(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment