Skip to content

Instantly share code, notes, and snippets.

@toruta39
Created May 8, 2013 08:05
Show Gist options
  • Save toruta39/5538954 to your computer and use it in GitHub Desktop.
Save toruta39/5538954 to your computer and use it in GitHub Desktop.
Get DataURL from SVG Element, supported on Chrome, Firefox, Opera, IE10+. stringencoders is needed on IE9-.
function getDataURLfromSVG (svg) {
var code = (new XMLSerializer).serializeToString(svg);
var b64 = window.btoa(unescape(encodeURIComponent(code))); // Workaround on UTF-8 char
return "data:image/svg+xml;base64," + b64;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment