Created
April 17, 2014 13:48
-
-
Save Tallmaris/10984840 to your computer and use it in GitHub Desktop.
Encode SVG as Image
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
function encodeSvgAsImg(divId) { | |
$("svg desc").remove(); | |
$("svg").removeAttr("xmlns"); | |
if ($("#"+divId).html().indexOf('xmlns') === -1) { | |
$("svg").attr("xmlns", "http://www.w3.org/2000/svg"); | |
} | |
var svg = $("#" + divId).html(); | |
var encoded = window.btoa(svg); | |
$("#" + divId) | |
.html("") | |
.append($("<img id='" + divId + | |
"' src='data:image/svg+xml;charset=utf8;base64," + encoded + | |
"' alt='wheel.svg' />")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment