I am converting SVG data to PNG. I am using the batik library Transcoder and PNGTranscoder classes.

I am able to perform the conversion, but the results are not coming across very well. First off, there are some arcs and curves in the original, and these are somewhat warped. I have compared the output of the batik Transcode to that of 'Inkscape", and the Inkscape results are much
cleaner, with the pixelated curves at least balanced and not distorted.

The Batik output also has some SVG artifacts. There are come rotated group in the source svg file. There are lines on these groups that should line up with lines elsewhere in the svg source, but the output PNG shows very obvious missalignments. Again, the reference
output of Inkscape shows no such artifacts.

The target application is a web site and the SVG conversion is done server site on a JSp server. The server is running linux. We do not have Inkscape on the server, and do not want to try and (go through the pain) to install it. I just mention it since it is an example of the svg to PNG
conversion, and we were expecting that the batik results would be similar.

A note on my environment: I am developing on MacOSX. I have not tried the batik library on another platform (on the off chance it is related to the OS). Other members of the development team that happen to use PCs (I know, right), have tried it and their results are the same, so there are at least two data
points that collaborate.

For reference, my code (which is quite simple), is shown below. I have stripped out some superfluous statements:

            PNGTranscoder png = new PNGTranscoder();
            Rectangle aoi = new Rectangle();
            aoi.x = x;
            aoi.y = y;
            aoi.width = w;
            aoi.height = h;
            png.addTranscodingHint(PNGTranscoder.KEY_AOI, aoi);
            BufferedReader istream = new BufferedReader
                    (new FileReader(svgTmpFile));
            log.info("ExportController Built BufferedReader.");
            TranscoderInput input = new TranscoderInput(istream);

FileOutputStream fout = new FileOutputStream("/tmp/Exported.png");
            TranscoderOutput fileOutput= new TranscoderOutput(fout);
            png.transcode(input,fileOutput);

            fout.flush();
            fout.close();

The only other option I know of is the option to set the Pixel size to MM, which relates to the pixel density. I could certainly increase this, but we really do not want huge images. If this is the "best option" however, perhaps it might be possible to perform the svg conversion at high
pixel density, then downsample?

Thank for the help!

Ed

Reply via email to