BatikServer SVG converter engine

This program starts a simple HTTP server on port 8282 (by default) that will accept requests to convert SVG files to bitmap formats (PNG and JPEG are currently supported).

Important: Because the SVG image file standard allows for external references to be made to image files and scripts etc., it is very important that you execute the JVM under a security policy that disallows linking to remote or local data that should not be exposed. The included security.policy file implements a basic security policy that may be sufficient, however it is not guaranteed.

Downloads

All of the downloads are available from the SourceForge download page.

Dependencies

The software was developed using Java 1.5, and as such will not build or run under a Java 1.4 JVM. Removing the generics should enable it to run however, if you're so inclined.

BatikServer depends on two external packages that must be installed either in your Java ext lib directory or in your CLASSPATH:

Batik handles rasterizing of the SVG files. Extract their binary and place 'batik.jar' in your classpath (it's just a manifest referencing the other .jar's and lib/ directory; you can't move it without those other files)

Simple provides a framework for HTTP serving and request handling. This may be replaced by custom code in the future. Download their package and place the jar file in your classpath.

The Ant build file expects the Batik in ext/batik.jar and Simple in ext/simple.jar for compilation. At runtime, modification of the security policy and/or classpath may be required.

Installation

Currently there aren't any support scripts included in the distribution. For a permanent installation, some though should be given to creating an appropriate init script to start the server. There also isn't a config file or command line argument parser yet, so it's just a matter of starting the JVM.

I haven't been able to work out how to make everything work when it's loaded in a jar either (it seems the dynamic class loading that occurs in Simple to start the service fails to find the class even though it is obviously included in the jar and available for static instantiation), suggestions appreciated.

For now, initiate the server with the following command, in the same directory as the class file root. Ensure that your CLASSPATH variable includes the Batik and Simple libraries as well as '.'.

$ java -Djava.security.manager -Djava.security.policy=../security.policy -server \
> org.ktims.batikd.BatikServer

The server will then be listening on 0.0.0.0:8282 for HTTP connections.

Use

Currently no client library is provided. The client implementation is quite trivial and can be done with minimal effort in most modern languages. The API consists of a number of HTTP URL parameters to control output, and an HTTP 'PUT' request to send the source SVG file.

URLS

URLs take the form of http://hostname:8282/format where format is a string defined by the output image format you would like to receive.

http://hostname:8282/pngproduces PNG output
http://hostname:8282/jpegproduces JPEG output

Parameters

The following parameters are available for any image type:

width:intThe maximum width of the output image
height:intThe maximum height of the output image
If one of these parameters is provided, the other must also be provided (the lone parameter will be ignored otherwise) and give the bounding box that the resized output must fit within. Aspect ratio is preserved and output size is adjusted so that this occurs.
max_width:intThe absolute maximum width of the output image
max_height:intThe absolute maximum height of the output image
These exist within the object to control the absolute maximum the program is willing to create. However, they have not yet been hidden from public view, allowing their use here.
bgcolor:stringThe background colour for transparency in the image; will be flattened for formats that don't support transparency. In format ffffff where the first 2 hexadecimal digits represent red, the second 2 green and the last 2 blue.
PNG Specific Parameters
white_trans:booleanForce the transparent background to be white. This is provided by Batik, I'm not exactly sure how it interacts with bgcolour.
indexed:intCreate an indexed output file? If non-zero, sets the number of bits to use for the colour (1,2,4,8)
JPEG Specific Parameters
quality:floatThe JPEG quality factor. Between 0 and 1. 1 indicates 100% quality.

Example Clients

PHP

require_once ('HTTP/Request.php');
$host = "localhost";
$port = 8282;
$svg = "test.svg";

$req = new HTTP_Request("http://$host:$port/png");
$req->setMethod(HTTP_REQUEST_METHOD_PUT);
// Force HTTP::Request to not multipart encode it
$req->addHeader("Content-Type", "image/svg");
// Resize to fit in 800x800
$req->addQueryString("width", 800);
$req->addQueryString("height", 800);

$req->addRawPostData(file_get_contents($svg));

// Send the image to the client
header("Content-Type: " + $req->getResponseHeader("Content-Type"));
echo $req->getResponseBody();

Python

from httplib import HTTPConnection

host = "localhost"
port = 8282
svg  = "test.svg"

req = HTTPConnection( host, port )
file = open( svg )
req.request( "PUT", "/png?width=800&height=800", file.read() )
resp = req.getresponse()

print resp.read()
Keenan Tims / ktims@gotroot.ca / 2006-03-28 / Valid XHTML Strict, CSS
SourceForge.net Logo