node-rsvg icon indicating copy to clipboard operation
node-rsvg copied to clipboard

Doesn't render <image> in output

Open psimyn opened this issue 9 years ago • 1 comments

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!

psimyn avatar Dec 02 '15 02:12 psimyn

Hi , please make sure you have valid svg data string. Its working as i copied directly from browser.

lavkesh1608 avatar Feb 26 '16 11:02 lavkesh1608