Created
April 6, 2017 13:34
-
-
Save elwinschmitz/d7801b0cb5dcb603f20b11b1561db997 to your computer and use it in GitHub Desktop.
Convert a SVG into CSS background-image url
This file contains hidden or 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
var svg = '<svg width="10" height="10" xmlns="http://www.w3.org/2000/svg"><circle fill="#F00" cx="5" cy="5" r="5"></circle></svg>'; | |
var url = 'data:image/svg+xml,' + encodeURI(svg).replace(/#/g, '%23').replace(/%20/g, ' ').replace(/%22/g, "'"); | |
console.log('background-image: url("' + url + '");'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment