Skip to content

Instantly share code, notes, and snippets.

@Tallmaris
Created April 17, 2014 13:48
Show Gist options
  • Save Tallmaris/10984840 to your computer and use it in GitHub Desktop.
Save Tallmaris/10984840 to your computer and use it in GitHub Desktop.
Encode SVG as Image
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