Answer the question
In order to leave comments, you need to log in
SVG string to createObjectURL?
When trying to create a blobUrl from a string, an error appears that swears at ampersands in the href of the image.
This is how I want to pass the svg string to the createObjectURL method:
const svgString = `
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1920" height="1080" viewBox="0 0 1920 1080" xml:space="preserve">
<desc>Created with Fabric.js 3.6.2</desc>
<defs>
</defs>
<rect x="0" y="0" width="100%" height="100%" fill="#151616"></rect>
<g transform="matrix(1 0 0 1 960 540)" >
<rect style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,255); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" x="-960" y="-540" rx="0" ry="0" width="1920" height="1080" />
</g>
<g transform="matrix(0.54 0 0 0.54 894.3 440)" >
<image style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" xlink:href="https://images.unsplash.com/photo-1587839443822-98fc3e351c22?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjIzOTk3fQ" x="-540" y="-810" width="1080" height="1620"></image>
</g>
</svg>
`
const blob = new Blob([svgString], { type: 'image/svg+xml' })
const url = URL.createObjectURL(blob)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question