Skip to content

Instantly share code, notes, and snippets.

@rbecheras
Forked from caged/svg-to-png.js
Created September 22, 2015 22:26
Show Gist options
  • Save rbecheras/7e71ec068717f3c4dee6 to your computer and use it in GitHub Desktop.
Save rbecheras/7e71ec068717f3c4dee6 to your computer and use it in GitHub Desktop.
Convert SVG's to PNGs. This works OK if the SVG's styles are inline. The SVG element must contain an xmlns attribute. Webkit also requires you specify a font size on `text` elements.
var svg = document.getElementById('graph'),
xml = new XMLSerializer().serializeToString(svg),
data = "data:image/svg+xml;base64," + btoa(xml),
img = new Image()
img.setAttribute('src', data)
document.body.appendChild(img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment