Skip to content

Instantly share code, notes, and snippets.

@nkint
Last active September 27, 2018 12:29
Show Gist options
  • Save nkint/3ea570bbc8ed4d42cc932a51249082f8 to your computer and use it in GitHub Desktop.
Save nkint/3ea570bbc8ed4d42cc932a51249082f8 to your computer and use it in GitHub Desktop.
Download canvas content as png
// TODO: does not handle `URL.revokeObjectURL`
function downloadCanvasContent(canvas: HTMLCanvasElement, filename: string) {
const link = document.createElement('a')
link.href = canvas.toDataURL()
link.download = filename
link.click()
}
const canvas = document.getElementById
downloadCanvasContent(canvas, 'test.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment