Skip to content

Instantly share code, notes, and snippets.

@tracend
Created June 28, 2016 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracend/3dea1aa9faaf9547ba5cc4231df1a1eb to your computer and use it in GitHub Desktop.
Save tracend/3dea1aa9faaf9547ba5cc4231df1a1eb to your computer and use it in GitHub Desktop.
Underscore mixin: SVGtoBase64
// Underscore mixin: SVGtoBase64
// Usage: background-image: url(data:image/svg+xml;base64,[output]);
_.mixin({
SVGtoBase64: function( svg ){
// fallback (to the first item in the document);
if( typeof svg != "string") svg = new XMLSerializer().serializeToString(document.getElementsByTagName("svg")[0]);
var base64 = window.btoa( svg );
// return the whole css line?
return base64;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment