node-rsvg
node-rsvg copied to clipboard
Doesn't render <image> in output
Using a data-uri as xlink:href, I am able to render/return an svg, which I can convert to png successfully using convert
in shell. But when calling render the image disappears, with apparently no errors.
var svg = ' \
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="100" height="100"> \
<image xlink:href="data:image/jpg;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" x="0" y="0" width="100" height="100" /> \
</svg>';
// this returns a working image
// res.set('Content-Type', 'image/svg+xml');
// return res.send(svg);
res.set('Content-Type', 'image/png');
var newsvg = new Rsvg(svg);
var svgString = newsvg.render({
format: 'png',
width: 100,
height: 100
}).data;
return res.send(svgString);
Happy to know if I am doing something completely wrong
Thanks!
Hi , please make sure you have valid svg data string. Its working as i copied directly from browser.