Skip to content

Instantly share code, notes, and snippets.

@tangoabcdelta
Created January 21, 2021 01:40
Show Gist options
  • Save tangoabcdelta/adeafcb1fa9bab3c7dee14fb0a438df7 to your computer and use it in GitHub Desktop.
Save tangoabcdelta/adeafcb1fa9bab3c7dee14fb0a438df7 to your computer and use it in GitHub Desktop.
HTML5 Canvas quick commands to export the contents to an image (as Data URI)
export the contents of a canvas as an image
img.src = document.getElementById('canvas').toDataURL();
// src will look like data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNb...
bonus: export by specifying the quality
canvas.toDataURL('image/jpeg', 1.0); // full
canvas.toDataURL('image/jpeg', 0.5); // medium
canvas.toDataURL('image/jpeg', 0.1); // low
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment