Search code examples
phpnode.jssvgd3.jsjquery-svg

svg to image on demand


I have javascript code that generates svg image tags on the fly when a person lands on one of the pages. Im using the d3 library to help make the image. The only problem is that d3 is not fully IE compatible and I would want to generate a .png, jpg, gif or any other image file based on the svg file. Is there a known way to do this? The server side code is PHP based, and we use node.js, and render.js for a lot of the dynamic content.


Solution

  • I'm using ImageMagick to convert SVG images to PNG images. This works pretty well.

    A quick example of how to do this:

    exec('/usr/bin/convert /path/to/image.svg /path/to/output_image.png');
    

    I'm using this with great success for processing QR codes made with libqrencode to different sizes and colors.