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 Lars Eirik Rønning <la...@gmail.com> on 2008/05/28 09:08:03 UTC
Manipulation of existing svg document
Hi.
I have an existing svg document where some of the nodes act as placeholders.
Basically these placeholders will be replaces with base64 encoded images.
1:Are there any convenience methods for adding images to an svg document or
do i have to manually base64encode the stream and add all attributes such as
widht and height?
I have already added an element using the SVGConstant for Images, but to mee
this still looks like its more or less the same as using any other
xmldocument.
If there are any guides or tutorials to using dom for handling images i am
very happy to receive some pointers..
2:One of my concerns is that i probably have to add the transformation
matrix myself. I was hoping that there could be some convenience methods
which would help me on my way for doing these types of operations.
Is the transformation matrix necessary in order for the image (or any
element) to be visible in a svg document?
Thanks for helping!
Lars
Re: Manipulation of existing svg document
Posted by Cameron McCormack <ca...@mcc.id.au>.
Lars Eirik Rønning:
> Thanks for helping.
> I actually wish to only open the file and get its base64encoding. Note that
> in my case i do not have bufferedImage, i merely wish to open the fileURI
> and have the bytes encoded to base64.
> I have found a base64Enocder class which may be used (org.apache.codec)
I’m not sure which class you are referring to here. (Batik doesn’t have
a class called Base64Encoder.)
> As i understand it the Base64EncoderStream class in Batik requires an
> renderedImage as input, but this is not what i am looking at.
No, it doesn’t (PNGImageEncoder does). You can write whatever bytes you
like to a Base64EncoderStream and it will output them as the base 64
bytes. So it sounds like you just want to open a FileInputStream and
feeds its bytes to a Base64EncoderStream.
> If i also understand you correct, the transform element is not required in
> order for an image to appear, only if i wish to do some transformation to
> the image, such as translating it or skewing and so forth.
That’s right. You will have to give it a width="" and height=""
attribute (and probably an x="" and y="", too) to tell it where in your
document it should render.
--
Cameron McCormack ≝ http://mcc.id.au/
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Manipulation of existing svg document
Posted by Lars Eirik Rønning <la...@gmail.com>.
Thanks for helping.
I actually wish to only open the file and get its base64encoding. Note that
in my case i do not have bufferedImage, i merely wish to open the fileURI
and have the bytes encoded to base64.
I have found a base64Enocder class which may be used (org.apache.codec)
As i understand it the Base64EncoderStream class in Batik requires an
renderedImage as input, but this is not what i am looking at.
If i also understand you correct, the transform element is not required in
order for an image to appear, only if i wish to do some transformation to
the image, such as translating it or skewing and so forth.
On Wed, May 28, 2008 at 10:07 AM, Cameron McCormack <ca...@mcc.id.au> wrote:
> Hi Lars.
>
> Lars Eirik Rønning:
> > I have an existing svg document where some of the nodes act as
> placeholders.
> > Basically these placeholders will be replaces with base64 encoded images.
> >
> > 1:Are there any convenience methods for adding images to an svg document
> or
> > do i have to manually base64encode the stream and add all attributes such
> as
> > widht and height?
> > I have already added an element using the SVGConstant for Images, but to
> mee
> > this still looks like its more or less the same as using any other
> > xmldocument.
>
> If you have, say, a BufferedImage and you want to convert it into a
> data: URI, you can do the following:
>
> BufferedImage img = …;
>
> ByteArrayOutputStream bytes = new ByteArrayOutputStream();
> Base64EncoderStream b64 = new Base64EncoderStream(bytes);
> PNGImageEncoder enc = new PNGImageEncoder(b64, null);
> enc.encode(img);
> b64.close();
>
> String uri = "data:image/png;base64," + bytes.toString();
>
> Then you can construct a new <image> element and set its xlink:href=""
> attribute to that URI. This is essentially what the SVGGraphics2D class
> does when it gets a drawImage() call.
>
> > If there are any guides or tutorials to using dom for handling images i
> am
> > very happy to receive some pointers..
> > 2:One of my concerns is that i probably have to add the transformation
> > matrix myself. I was hoping that there could be some convenience methods
> > which would help me on my way for doing these types of operations.
> > Is the transformation matrix necessary in order for the image (or any
> > element) to be visible in a svg document?
>
> I'm not quite sure what you want to achieve, so I don't know whether you
> need to set a transform='" on the <image> elements or not.
>
> --
> Cameron McCormack ≝ http://mcc.id.au/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
Re: Manipulation of existing svg document
Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Lars.
Lars Eirik Rønning:
> I have an existing svg document where some of the nodes act as placeholders.
> Basically these placeholders will be replaces with base64 encoded images.
>
> 1:Are there any convenience methods for adding images to an svg document or
> do i have to manually base64encode the stream and add all attributes such as
> widht and height?
> I have already added an element using the SVGConstant for Images, but to mee
> this still looks like its more or less the same as using any other
> xmldocument.
If you have, say, a BufferedImage and you want to convert it into a
data: URI, you can do the following:
BufferedImage img = …;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Base64EncoderStream b64 = new Base64EncoderStream(bytes);
PNGImageEncoder enc = new PNGImageEncoder(b64, null);
enc.encode(img);
b64.close();
String uri = "data:image/png;base64," + bytes.toString();
Then you can construct a new <image> element and set its xlink:href=""
attribute to that URI. This is essentially what the SVGGraphics2D class
does when it gets a drawImage() call.
> If there are any guides or tutorials to using dom for handling images i am
> very happy to receive some pointers..
> 2:One of my concerns is that i probably have to add the transformation
> matrix myself. I was hoping that there could be some convenience methods
> which would help me on my way for doing these types of operations.
> Is the transformation matrix necessary in order for the image (or any
> element) to be visible in a svg document?
I’m not quite sure what you want to achieve, so I don’t know whether you
need to set a transform='" on the <image> elements or not.
--
Cameron McCormack ≝ http://mcc.id.au/
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org