![](https://secure.gravatar.com/avatar/15f5e6abf26f57e1838c29a8356ce7f8.jpg?s=120&d=mm&r=g)
Hello Inkscape developers!
Great work :)
I love svg & inkscape, and I'm currently playing with dynamically altering svgs (created with inkscape) under php. Now i am facing the problem of converting these svgs to raster graphics (png, jpg) using only php and gd on a web server.
I googled but did not find any approach in this direction. There is a gd extension for creating svgs from gd commands, but not the other way round.
Anyone know a possibility of doing this?
If there really is no such library yet, I am ready to take a stab at it myself. Do you think porting some inkscape code to php (of course preserving the GNU license) is a manageabel and promising approach?
I'd be grateful for any comments, links or reccomendations.
Regards, Tobias
P.S.: I have three reasons for wanting to convert from svg to raster before serving: Old browsers not supporting svg, dumb users not being able to handle them, and protecting original fully-scalable artwork.
![](https://secure.gravatar.com/avatar/329be97b2bd13d72df03107e60678241.jpg?s=120&d=mm&r=g)
I googled but did not find any approach in this direction. There is a gd extension for creating svgs from gd commands, but not the other way round.
Anyone know a possibility of doing this?
Just a guess (not a dev) you can use inkscape as a command line app. I'm sure it will turn an svg into a png.
/d
![](https://secure.gravatar.com/avatar/eb3fe37da4a199eb4e3b479d8a57f808.jpg?s=120&d=mm&r=g)
On Wed, 28 Mar 2007 18:54:13 +0200, Donn <donn.ingle@...400...> wrote:
Just a guess (not a dev) you can use inkscape as a command line app. I'm sure it will turn an svg into a png.
Yep! For instance:
inkscape some.svg --export-png=some.png
There's a more detailed description of the various command line options here:
http://www.inkscape.org/doc/inkscape-man.html
-mental
![](https://secure.gravatar.com/avatar/8d5128b5b838ecedc34635fba7995f7f.jpg?s=120&d=mm&r=g)
On Wed, Mar 28, 2007 at 06:44:45PM +0200, vin@...1705... wrote:
Hello Inkscape developers!
Great work :)
I love svg & inkscape, and I'm currently playing with dynamically altering svgs (created with inkscape) under php. Now i am facing the problem of converting these svgs to raster graphics (png, jpg) using only php and gd on a web server.
I googled but did not find any approach in this direction. There is a gd extension for creating svgs from gd commands, but not the other way round.
Anyone know a possibility of doing this?
If there really is no such library yet, I am ready to take a stab at it myself. Do you think porting some inkscape code to php (of course preserving the GNU license) is a manageabel and promising approach?
I'd be grateful for any comments, links or reccomendations.
I've experimented around with a number of different approaches for doing this, each with their pluses and minuses.
As others pointed out, inkscape can be run from the commandline. This gives good quality results, and there's few problems with stuff that doesn't render. It does have a number of commandline options for controlling what gets exported. The downside is that inkscape isn't a very lightweight solution.
Cairo has an svg2png tool that is quite lightweight, and supports most of Inkscape's SVG features, but there might be some minor rendering discrepancies.
Imagemagick is a good choice for server-side image processing. It has some support for SVG, but I wasn't that impressed with it; it supports a subset of available SVG features.
I haven't played with gd's svg support, but expect it'd be on the level of imagemagick; possibly it uses the same backend for svg processing.
For manipulating the SVG content itself, depending on your needs, most likely what you'll want is php's xpath library rather than the above renderers. There are some SVG manipulation libraries, though I haven't heard of one for PHP.
Hoep this helps, Bryce
![](https://secure.gravatar.com/avatar/bf3e659060fcd15f018a6a19cea51084.jpg?s=120&d=mm&r=g)
I had this same issue with Rails (since Rails is not supporting SVG yet) - my approach was to use ImageMagick which works great and gives many options. But I received an email from Ted who reminded me I could also use Inkscape. Probably depends, if you have ImageMagick already on your server, then that would be a logical choice.
Bryce Harrington wrote:
On Wed, Mar 28, 2007 at 06:44:45PM +0200, vin@...1705... wrote:
Hello Inkscape developers!
Great work :)
I love svg & inkscape, and I'm currently playing with dynamically altering svgs (created with inkscape) under php. Now i am facing the problem of converting these svgs to raster graphics (png, jpg) using only php and gd on a web server.
I googled but did not find any approach in this direction. There is a gd extension for creating svgs from gd commands, but not the other way round.
Anyone know a possibility of doing this?
If there really is no such library yet, I am ready to take a stab at it myself. Do you think porting some inkscape code to php (of course preserving the GNU license) is a manageabel and promising approach?
I'd be grateful for any comments, links or reccomendations.
I've experimented around with a number of different approaches for doing this, each with their pluses and minuses.
As others pointed out, inkscape can be run from the commandline. This gives good quality results, and there's few problems with stuff that doesn't render. It does have a number of commandline options for controlling what gets exported. The downside is that inkscape isn't a very lightweight solution.
Cairo has an svg2png tool that is quite lightweight, and supports most of Inkscape's SVG features, but there might be some minor rendering discrepancies.
Imagemagick is a good choice for server-side image processing. It has some support for SVG, but I wasn't that impressed with it; it supports a subset of available SVG features.
I haven't played with gd's svg support, but expect it'd be on the level of imagemagick; possibly it uses the same backend for svg processing.
For manipulating the SVG content itself, depending on your needs, most likely what you'll want is php's xpath library rather than the above renderers. There are some SVG manipulation libraries, though I haven't heard of one for PHP.
Hoep this helps, Bryce
Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=D... _______________________________________________ Inkscape-devel mailing list Inkscape-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/inkscape-devel
![](https://secure.gravatar.com/avatar/f90333bfcbc0a7fa19cedbe5283235a3.jpg?s=120&d=mm&r=g)
BH> I've experimented around with a number of different approaches for doing BH> this, each with their pluses and minuses.
Thanks! I'll have a look at them. However, my major goal, finding or implementig a solution that works under PHP+GD without using other software is still unsolved.
I'm just wondering if porting parts of the Inkscape code to php is somehow realistic, and thought i'd ask before actually trying it.
regards, Tobias
![](https://secure.gravatar.com/avatar/8d5128b5b838ecedc34635fba7995f7f.jpg?s=120&d=mm&r=g)
On Fri, Mar 30, 2007 at 09:21:28PM +0200, Tobias Damisch wrote:
BH> I've experimented around with a number of different approaches for doing BH> this, each with their pluses and minuses.
Thanks! I'll have a look at them. However, my major goal, finding or implementig a solution that works under PHP+GD without using other software is still unsolved.
I'm just wondering if porting parts of the Inkscape code to php is somehow realistic, and thought i'd ask before actually trying it.
I wouldn't think it a realistic solution, since the Inkscape code for parsing and interpreting SVG, and then rendering it into a bitmap is quite sophisticated. I don't know how many lines of code are involved, but think it's well beyond what one person could easily handle.
I don't know what requirements are limiting you to PHP+GD for this, but it may be worthwhile to push back to get an allowance to add cairo (or Inkscape itself), and then look for some php code that interfaces to that. Even if no cairo-php exists, it'd be easier to code to than porting Inkscape's internals to php by a few orders of magnitude.
Bryce
![](https://secure.gravatar.com/avatar/f90333bfcbc0a7fa19cedbe5283235a3.jpg?s=120&d=mm&r=g)
Hello Bryce,
Yeah, I had a look at the code, and you're probably right. Thanks for the advice!
Tobias
Friday, March 30, 2007, 11:19:47 PM, you wrote:
BH> On Fri, Mar 30, 2007 at 09:21:28PM +0200, Tobias Damisch wrote:
BH> I've experimented around with a number of different approaches for doing BH> this, each with their pluses and minuses.
Thanks! I'll have a look at them. However, my major goal, finding or implementig a solution that works under PHP+GD without using other software is still unsolved.
I'm just wondering if porting parts of the Inkscape code to php is somehow realistic, and thought i'd ask before actually trying it.
BH> I wouldn't think it a realistic solution, since the Inkscape code for BH> parsing and interpreting SVG, and then rendering it into a bitmap is BH> quite sophisticated. I don't know how many lines of code are involved, BH> but think it's well beyond what one person could easily handle.
BH> I don't know what requirements are limiting you to PHP+GD for this, but BH> it may be worthwhile to push back to get an allowance to add cairo (or BH> Inkscape itself), and then look for some php code that interfaces to BH> that. Even if no cairo-php exists, it'd be easier to code to than BH> porting Inkscape's internals to php by a few orders of magnitude.
BH> Bryce
participants (6)
-
unknown@example.com
-
Bryce Harrington
-
Donn
-
jtaber
-
MenTaLguY
-
Tobias Damisch