Skip to content

Instantly share code, notes, and snippets.

@sharunkumar
Last active May 8, 2021 21:02
Show Gist options
  • Save sharunkumar/fdcfe73cf0921a28ca2633162317cce5 to your computer and use it in GitHub Desktop.
Save sharunkumar/fdcfe73cf0921a28ca2633162317cce5 to your computer and use it in GitHub Desktop.
Dev tools snippet to convert svg element contents to image data url which can then be saved or copied
// Modified version of code from where I got this: https://ourcodeworld.com/articles/read/1072/how-to-convert-a-html-svg-node-to-base64-with-javascript-in-the-browser
// $0 gets the currently selected element in 'inspect element' mode in dev tools. make sure you have selected the SVG tag element
var serializedSVG = new XMLSerializer().serializeToString($0);
var base64Data = window.btoa(serializedSVG);
// printing on to console which would be a clickable link
console.log("data:image/svg+xml;base64," + base64Data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment