views:

160

answers:

2

I have drawn an icon in Inkscape, but would now like to programmatically alter it (change the colours slightly for different icon states) and convert it to a tiled PNG format file containing multiple icons with different colours. I know about Inkscape's --export-png options, but can't see a way to make it change the image and/or export multiple times to different parts of the combined image.

Are there any good user-oriented tools for programmatically fiddling with images, or do I have to delve into GD or even manually modifying the SVG XML?

+3  A: 

Even though I'm not 100% sure if it fulfills your request for user-orientation, I recommend you to have a look at www.imagemagick.org. I have successfully used its "convert" utility for scripting conversion from svg to png and also for adding custom background colors.

norheim.se
A: 

I use two simple sets of tools to do this for a webcomic:

  • Basic Perl/PHP/Ruby scripts to modify the SVG XML (there is also a great Perl library, but I find it isn't needed for the basic changes I need)
  • Run Inkscape itself from the command line to render the SVG to PNG. Inkscape's SVG rendering is by far the best I have found.

Note: Inkscape can be installed on a webserver with a bit of work and can be called from a CGI (perl, php, etc.), though it's slow (so you should cache the results).

Calling it from the command line on a directory of SVG files:

find -name "*svg" -exec inkscape -z --file={} \ 
    --export-png=$OUTPUT{}.png --export-width=640 --vacuum-defs \;
  • Finds all SVG files
  • Runs Inkscape to render each file
  • Width is limited to 640px
  • The SVG files are cleaned up (nice to do before checking into svn/git)

You may also be interested in Batik, an SVG render engine written in Java. It runs nicely on the server side, and is fairly self-contained.

Bruce Alderson