Search code examples
javascriptsvgnpmpngsharp

SVG with external png inside to PNG in Node


Is there a node-package which is able to convert an svg to png from an external image inside the svg-file like this?

<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 120 120" height="120" width="120"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">

  <rect x="0" y="0" width="120" height="120" fill="lightgreen"/>

  <image xlink:href="https://upload.wikimedia.org/wikipedia/commons/d/d6/MicroQR_Example.png" x="10" y="10" width="100px"/>

</svg>

At the moment I use http://sharp.dimens.io/ for the conversion, but I could not find a way to resize and save it to a png without loosing the inner external image: onnly the rect is visible afterwards. :/

It would be nice if you could tell me any package I could use to get the above code working :)

Thanks in advance.


Solution

  • Finally i got an solution, on my Mac i had to install some additional packages, now it's running: https://github.com/lovell/package-libvips-darwin/blob/master/.travis.yml