You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Edward Henderson <ku...@me.com> on 2011/10/04 16:39:26 UTC

SVG to PNG Conversion Quality and artifacts

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

Re: SVG to PNG Conversion Quality and artifacts

Posted by Martin J <ja...@gmail.com>.
The quality of the rendering is ENTIRELY dependent on the underlying
graphics 'engine' -- I have had excellent results when running my
server on Mac OS X, and very disappointing results on Linux (Ubuntu,
Headless). The worst of all was text rendering, where the renderer did
no anti-aliasing and text was jaggy.

I never solved the problem, but it's clearly an OS-related issue,
rather than Batik.

Sorry,
Martin

On 4 October 2011 17:39, Edward Henderson <ku...@me.com> wrote:
> 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
>



-- 
>From my MacBook Pro

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org