Skip to content

Instantly share code, notes, and snippets.

@klcodanr
Created September 16, 2019 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klcodanr/2fbfc9b1ea369ad42b62cbe0aeb6ea09 to your computer and use it in GitHub Desktop.
Save klcodanr/2fbfc9b1ea369ad42b62cbe0aeb6ea09 to your computer and use it in GitHub Desktop.
function svg2img(){
var svg = document.querySelector('svg');
var xml = new XMLSerializer().serializeToString(svg);
var svg64 = btoa(xml);
var b64start = 'data:image/svg+xml;base64,';
var image64 = b64start + svg64;
return image64;
};
var img = document.createElement('img');
img.src = svg2img();
document.body.appendChild(img);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment