Discussion:
Svg to png rasterizer resolution - output blurry
Woods, Christopher
2006-01-10 19:32:10 UTC
Permalink
Hi,

I'm using batik 1.6 to convert a directory of .svg images to .png with
the following command:

java -jar batik-rasterizer.jar -d myDir -m image/png -dpi 300
samples/*.svg

The result is blurry .png images. I suspect the -dpi option is to blame
as the resulting file sizes are the same as when I specify no -dpi
option (I understand the default is 96 dpi). Can anyone point me in the
right direction. Thanks very much. Cheers.

chris
Jay Baldwin
2006-01-10 22:27:11 UTC
Permalink
I am just getting started with both SVG manipulation and Batik, mostly
relevant to what you're doing however. We are starting to be supplied
SVG images, in fairly large numbers, for the publications we produce;
but we need raster for our layout/composition engine.

Since SVG is more or less device independent, it's confusing as to how
to "scale up" the SVG in memory before a conversion to raster. With one
set of files, I found that I had to do some manipulation of some
attributes to make them "larger" in memory for batik-rasterizer. For
example, one set of files had size attributes like this:

<svg viewBox="2.145927 -6.520668 1.79657 1.452484" width="100%"
height="100%" ... >

I don't know what application wrote these, but those unqualified values
default to pixels according to SVG standard as I understand it (maybe
the controlling application has "preference settings" to interpret these
as inches, which they obviously are intended to be). But without that
application, they are just px to Batik. So I wrote some basic perl to
convert the above to:

<svg viewBox="2.145927 -6.520668 1.79657 1.452484" width="1.79657in"
height="1.452484in" ... >

As I understand it, the unit of measure used on the "width" and "height"
properties on the root svg element is inherited as the default unit of
measure by the rest of the svg. So specifying the unit of measure here
is very powerful and appears to be all I had to do to the whole file.

After doing this, my results from batik-rasterizer were much better. I
realize this is not much more than a hack, but since no one else has
jumped in with a better answer, I thought I'd offer up what little I
know so far.

Another curious thing... since SVG really does have this
device-independent scalability and is pixel-oriented, I discovered that
if instead of using batik-rasterizer, you open an SVG in squiggle,
maximize it to your full screen, then export it as jpeg or tiff, that
your resulting raster image is of much higher quality than if you did
not maximize the window. No actions or menu selections, just "making
the window bigger".

If any of the much wiser and more experienced folks here know of better
ways and/or better "tricks" to produce print-quality raster images from
SVG source images and batik-rasterizer, I'd love to hear about it, too.

Jay Baldwin
Application Development Team Leader
***************************************************
Tweddle Litho Company
24700 Maplehurst, Clinton Twp, MI 48036-1336
+1.586.840.1324
http://www.tweddle.com/



-----Original Message-----
From: Woods, Christopher [mailto:***@EO.Kollmorgen.com]
Sent: Tuesday, January 10, 2006 2:32 PM
To: batik-***@xmlgraphics.apache.org
Subject: Svg to png rasterizer resolution - output blurry

Hi,

I'm using batik 1.6 to convert a directory of .svg images to .png with
the following command:

java -jar batik-rasterizer.jar -d myDir -m image/png -dpi 300
samples/*.svg

The result is blurry .png images. I suspect the -dpi option is to blame
as the resulting file sizes are the same as when I specify no -dpi
option (I understand the default is 96 dpi). Can anyone point me in the
right direction. Thanks very much. Cheers.

chris

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-***@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-***@xmlgraphics.apache.org
Andreas Neumann
2006-01-10 23:09:34 UTC
Permalink
Hi,

if you have a svg-root element like you specified (

<svg viewBox="2.145927 -6.520668 1.79657 1.452484" width="100%"
height="100%" ... >

)

, you don't need to replace the width and height to a certain value. No
need to pre-process the SVGs. Note that you need a viewBox and need to
set the width and height to "100%".

Just use the -w and -h switches of the batik rasterizer as documented at
http://xml.apache.org/batik/svgrasterizer.html.

As an example, open the samples/mapSpain.svg file that comes with the
batik distribution and edit the width and height attribute to set it to
"100%".

Then start the rasterizer as follows:

java -jar batik-rasterizer.jar -w 6000 -h 4200 samples/mapSpain.svg -m
image/png -d spain.png -bg 255.255.255.255

and you get a crisp output in png that scales to your given width and
height in pixel.

Please note that you need to increase the amount of memory that the
batik-rasterizer has at hand if you want to process medium to big file
sizes or big raster files as output.

Another option to "scale" your image to a given width and height is to
write a wrapper xsl-fo document and include the svg there. That way you
can also generate multipage documents.

Hope, this helps,

Andreas
--
----------------------------------------------
Andreas Neumann - Institute of Cartography
Swiss Federal Institute of Technology (ETH)
ETH Hoenggerberg
CH-8093 Zurich, Switzerland
Phone: ++41-1-633 3031, Fax: ++41-1-633 1153
e-mail: ***@karto.baug.ethz.ch
www: http://www.carto.net/neumann/
SVG.Open: http://www.svgopen.org/
Carto.net: http://www.carto.net/
Woods, Christopher
2006-01-11 15:02:11 UTC
Permalink
Thanks to Andreas and Jay for their replies as it turns out their advice
was correct but my problem was one entirely different from what I
described in the first post to this thread.

A typical root from my batch of svgs looks like this:

<svg width="856.085" height="317.649" viewBox="0 0 856.085 317.649">

The result from Batik without specifying -h, -w, or -dpi options is
perfectly clear. I discovered this by viewing the files outside the
publication they belong to (note-to-self: ALWAYS CHECK THE FILE OUTSIDE
ITS TARGET PUBLICATION TO BE SURE THE PROBLEM IS THE IMAGE AND NOT SOME
ARTIFACT OF THE XHTML!).

The poor resolution was the result of the height and width attributes in
the <img/> tag in the target publication which caused the image to be
stretched to fit a space larger than its original output dimensions.
Thus the blurry output. I'm going back to re-write the applicable
portion of the XSL transform so that the <img/> tag attributes do not
exceed the actual image dimensions.

In the end the problem lay in the XSL transform that produced the XHTML
page the image belonged to and not the image itself. Batik works like a
top; my troubleshooting methodology on the other hand...

Thanks again to Jay and Andreas for taking the time to reply to my first
post.

Cheers,

Chris

-----Original Message-----
From: Andreas Neumann [mailto:***@karto.baug.ethz.ch]
Sent: Tuesday, January 10, 2006 6:10 PM
To: batik-***@xmlgraphics.apache.org
Subject: Re: Svg to png rasterizer resolution - output blurry

Hi,

if you have a svg-root element like you specified (

<svg viewBox="2.145927 -6.520668 1.79657 1.452484" width="100%"
height="100%" ... >

)

, you don't need to replace the width and height to a certain value. No
need to pre-process the SVGs. Note that you need a viewBox and need to
set the width and height to "100%".

Just use the -w and -h switches of the batik rasterizer as documented at
http://xml.apache.org/batik/svgrasterizer.html.

As an example, open the samples/mapSpain.svg file that comes with the
batik distribution and edit the width and height attribute to set it to
"100%".

Then start the rasterizer as follows:

java -jar batik-rasterizer.jar -w 6000 -h 4200 samples/mapSpain.svg -m
image/png -d spain.png -bg 255.255.255.255

and you get a crisp output in png that scales to your given width and
height in pixel.

Please note that you need to increase the amount of memory that the
batik-rasterizer has at hand if you want to process medium to big file
sizes or big raster files as output.

Another option to "scale" your image to a given width and height is to
write a wrapper xsl-fo document and include the svg there. That way you
can also generate multipage documents.

Hope, this helps,

Andreas



--
----------------------------------------------
Andreas Neumann - Institute of Cartography Swiss Federal Institute of
Technology (ETH) ETH Hoenggerberg
CH-8093 Zurich, Switzerland
Phone: ++41-1-633 3031, Fax: ++41-1-633 1153
e-mail: ***@karto.baug.ethz.ch
www: http://www.carto.net/neumann/
SVG.Open: http://www.svgopen.org/
Carto.net: http://www.carto.net/


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