Created
October 23, 2013 16:02
-
-
Save iwek/7121463 to your computer and use it in GitHub Desktop.
D3 click function to save SVG as dataurl in IMG tag
This file contains 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
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For SVG to Image Conversion: http://techslides.com/save-svg-as-an-image/