views:

208

answers:

1

I'm attempting to scale an image, modify it, and then output to another image format. So far, I've been using the apache batik library. For simple conversion, this is easy. For clipping the svg, this is easy.

However, I can't seem to figure out how to scale to the full image created by the svg. That is, I can specify the area of interest as a bounding rectangle, and then scaling works over the bounding rectangle, but I do NOT know how to scale over the image of the svg.

This is what I have so far:

...
//set the output width and height  
transcoder.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( newSize.width ) );
transcoder.addTranscodingHint( PNGTranscoder.KEY_HEIGHT, new Float( newSize.height ) );

//set the aoi for scaling. Unsure what to do here.
transcoder.addTranscodingHint( PNGTranscoder.KEY_AOI, new Rectangle( 0, 0, 100, 100 ) );
...
+1  A: 

If you don't set the KEY_AOI transcoding hint, then the viewBox="" attribute on the root <svg> element will be used to determine the area of interest. If the document you are transcoding doesn't have have a viewBox="" attribute, then the width="" and height="" attributes will be used, so the AOI will be (0, 0, width, height).

And if none of these are set, and you don't know in advance where within the document's coordinate system the graphics are, then you could compute the bounding box of the root <svg> element and use that as the AOI. You could do this by first "booting the DOM" for your document, and then calling getBBox() on the document element.

heycam
Since I'll be dealing with a variety of SVG images, I'll probably have to do all 3 of these. Thanks for the quick response. I'll accept once I can test this.
Stefan Kendall