Last active
September 19, 2024 13:42
-
-
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
This file contains hidden or 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
// 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
#