Skip to content

Instantly share code, notes, and snippets.

@iwek
Created October 23, 2013 16:02
Show Gist options
  • Save iwek/7121463 to your computer and use it in GitHub Desktop.
Save iwek/7121463 to your computer and use it in GitHub Desktop.
D3 click function to save SVG as dataurl in IMG tag
d3.select("#save").on("click", function(){
var html = d3.select("svg")
.attr("version", 1.1)
.attr("xmlns", "http://www.w3.org/2000/svg")
.node().parentNode.innerHTML;
//console.log(html);
var imgsrc = 'data:image/svg+xml;base64,'+ btoa(html);
var img = '<img src="'+imgsrc+'">';
d3.select("#svgdataurl").html(img);
});
@iwek
Copy link
Author

iwek commented Oct 23, 2013

For SVG to Image Conversion: http://techslides.com/save-svg-as-an-image/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment