views:

64

answers:

2

I'm working on a project in PHP that needs to render dynamically-created SVG images to PNG (or GIF if not PNG) format. I know I can do this by invoking a SVG renderer like rsvg, or with an extension like ImageMagick, which isn't that common*.

Is there a "drop-in" style library that can render SVG using things like GD and DomDocument?

* Available in common webhosts and in packages like XAMPP.

To clarify, I already have the SVG itself generated, I just need it to be rendered server-size.

+1  A: 

It shouldn't be too hard to do yourself. SVG is a fairly simple specification, so there shouldn't be too much guess work building a converter... The only difficult parts that I can see would be gradients, markers and filters. The rest should be relatively straight forward when looking at the gd functions available.

Obviously, the best would be to find a stand alone library, but if you can't you could always roll one yourself...

ircmaxell
Well, I have tried my hand at this, but gotten hung up at [the path specification](http://www.w3.org/TR/SVG/paths.html).
MiffTheFox
Well, it's all just a state engine. You start at a point. Then you can either move to another point, draw a line to another point or draw a curve to another point (the curve functions will take some thought, but they are quite doable). The rest of the path specification is really quite straight forward. And the spec you link should have enough info for you to be able to come up with something half way decent...
ircmaxell
A: 

If you have Java on the server, you can use Batik's SVG Rasterizer, which comes as a standalone executable JAR. Call it using PHP exec.

echo-flow
This seems like a doable idea. Java is pretty much everywhere, and a JAR can be uploaded with the scripts. I shall attempt it when I can.
MiffTheFox