Skip to content

Instantly share code, notes, and snippets.

@garciparedes
Created June 27, 2022 09:42
Show Gist options
  • Select an option

  • Save garciparedes/34a8adae99d88b817da79f3b07111664 to your computer and use it in GitHub Desktop.

Select an option

Save garciparedes/34a8adae99d88b817da79f3b07111664 to your computer and use it in GitHub Desktop.
Download all named `canvas` elements as png images.
const elements = document
.getElementsByTagName("canvas");
for (let element of elements) {
if (!element.id) {
continue;
}
const image = element
.toDataURL("image/png")
.replace("image/png", "image/octet-stream");
const a = document
.createElement("a");
a.href = image;
a.download = `${element.id}.png`;
a.click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment