Batik Rasterizing

chrimble on 2003-06-25T14:36:31

SVG is great fun. Gone are the days of faffing about in the Gimp trying to make consistant-looking buttons for my website - now it's simply a matter of knocking out a quick script that outputs some appropriate SVG ready for conversion into a bitmap format.

For that purpose, I use the batik rasteriser. Whilst it's java-based and no speed demon, it produces some nice output, and it's fairly easy to get good results. Unfortunately, it also requires a connection to an X server as it relies on the AWT for some of its functions - even the command line tools such as the rasterizer. Nothing appears on the screen - it just needs the X connection otherwise a fatal exception is raised.

So I've been down a merry "xhost + [machine]" route whilst setting the DISPLAY environment variable to point back my workstation from the development box (no X). This is officially Inconvenient, and I've been grumbling about it for a while. The previous official "solution" to this problem was to set up xvfb and use that. Again, Inconvenient.

Happily though, today I found a proper solution. Java 1.4 has introduced a "headless" mode which can be activated by adding a simple "-Djava.awt.headless=true" flag to the java call that runs the rasterizer. Yay!

So I thought I'd put it here in case I needed to remember it again. ;-)


Doesn't work with all methods though.

nyquist on 2003-06-25T15:24:11

Unfortuantely, only MOST of the AWT methods work in this mode. For the few that still require connectivity to an X server, it will then throw a HeadlessException instead of just a general Exception, so you have some idea what the underlying failure was about. (i.e. "You used an AWT method that requires an X server.")