Advertisement
nzisaacnz

SVG to data url

Nov 28th, 2016
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.54 KB | None | 0 0
  1. <style>
  2. svg,img{
  3.   border: 3px dashed black;
  4. }
  5. textarea{
  6. width:50%;
  7. height:300px;
  8. }
  9. </style>
  10. <svg id="placeholder"xmlns="http://www.w3.org/2000/svg"width="135"height="13"><text x="0"y="10"font-family="Verdana"font-size="12" fill ="#acacac">Some Text</text></svg>
  11. <br>
  12. <img id="img">
  13. <br>
  14. <textarea id="result"></textarea>
  15. <script>
  16. var text = placeholder.outerHTML;
  17.  var url = "data:image/svg+xml;,"+text.replace(/id="placeholder"/g," ").replace(/\n|([ ] )/g,"");//.replace(/" /g,"\"");
  18. img.src = url;
  19. result.value = url;
  20. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement