Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 969
Jdahern Avatar asked Jul 05 '12 19:07

Jdahern


1 Answers

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.

like image 100
Repox Avatar answered Oct 06 '22 00:10

Repox