tags:

views:

416

answers:

2

I am currently struggling with a side project I hope you can help me with.

I am trying to convert SVG images to JPEG with PHP4.

Originally I tried to interface java with php via the php_java.dll and jar that comes with PHP 4.2.2 but while I never got any warnings I never managed to get even the simplest test working. All text regarding it is for JDK1.4 and an article on setting it up on O'Reilly website is for JDK1.2. That would of enabled me to use Batik.

So I then looked harder and saw cryptic references to using PHP:GD to convert SVG to JPEG. GD seems to be able to load and save JPEG, PNG, GIF, etc, but not SVG directly. GD seems to use a vector graphics format but not entirely sure if it is SVG compatible (I am a noob to both).

I did find a Perl GD::SVG module, but obviously requires Perl - and considering the problems I had with PHP<->Java I am loathe to go that route.

I also found a site (which I can't find now) that discussed speed of various SVG conversions with rsvg, Cairo and a couple of others. Talking of applications converting SVG to JPEG, people also discuss ImageMagick. While that might work on the linux box that is the server, I do 99% of my development in Windows - hence prefering a pure PHP solution and not wrestling with differences between applications on different platforms.

I am now considering writing a SVG->GD converter. The final alternative is to use SVG in the browser via Raphael. I'd rather convert to JPEG on the server and serve the image normally.

Has anyone had any use of SVG->GD, know of any OS (but not GPL) convertors or have any better ideas?

+1  A: 

It's not maintained, and I can't vouch for it, but you didn't mention this option. It sounds like what you were trying to do with Batik.

http://pear.php.net/package/XML_svg2image/

Don't know if this helps or not.

easement
That was what I was trying to do with Batik.
graham.reeds
A: 

I finally manage to fix it by actually downloading and installing the 1.4 JDK from Sun's archive. Worked no problem. Something must of changed between 1.4 and 1.6.14 but I am glad I got it working.

Also while researching a blog post on this subject I came across Image_Canvas which might be a better (ie it is written in PHP) option.

graham.reeds