Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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