Skip to main content

Running gimp in batch mode to convert SVG to PNG files

Years ago for the NCCP website, I needed to generate charts that would appear as vector graphics (in PDF files) and as raster graphics (in PNG's).

The best solution at the time -- it may not be so any more -- was to write my own library of graph-drawing functions that generated SVG files, then run the GIMP in batch mode to convert those images to PNG files. (I know... I had a lot of time on my hands.)

That was all configured back in 2006/7, and has been running smoothly ever since. Then our server crashed, and I've been stuck trying to recreate the environment from the old server. Just in case (g-d forbid) that should ever happen again, here's what it took to get the SVG-to-raster conversion working again:

  • Installed GIMP (simple, using up2date)
  • At this point I ran into trouble because GIMP has to run once in GUI mode for the current user before it can be run from the command line. A very helpful Rackspace tech did this for me as root and copied the settings directory from /root to /var/www so that it would work when apache was running.
  • I then realized that the command I was using -- svg-to-raster -- was not built in to GIMP, but a custom function. It needed to be downloaded here and configured and run according to those directions.

All in all, it didn't take long to get up and running, but it could have been much more painful!