cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Markus <t.mar...@proventis.net>
Subject Re: Streaming buffered image using Cocoon
Date Mon, 23 May 2011 06:28:24 GMT
Hi,

thats pretty simple. Create a reader like this (creates a png with 
current timestamp in red):

public class TestImageReader extends AbstractReader {

     public String getMimeType() {
         return "image/png";
     }

     public void generate() throws IOException, SAXException, 
ProcessingException {
         String date = DateFormat.getDateTimeInstance().format(new Date());
         Font font = Font.decode(Font.SERIF).deriveFont(80.f);
         TextLayout textLayout = new TextLayout(date, font, new 
FontRenderContext(null, true, true));
         Rectangle2D bounds = textLayout.getBounds();
         BufferedImage image = new BufferedImage((int) 
bounds.getWidth(), (int) bounds.getHeight(), BufferedImage.TYPE_INT_ARGB);
         Graphics2D g = image.createGraphics();
         g.setColor(Color.RED);
         textLayout.draw(g, (float) -bounds.getX(), (float) -bounds.getY());
         g.dispose();
         ImageIO.write(image, "png", this.out);
     }

}

in your sitemap define and use this reader:
<map:components>
<map:readers>
<map:reader name="timeimg" src="test.TestImageReader" />
</map:readers>
</map:components>

...

<map:match pattern="time.jpg">
   <map:read type="timeimg" />
</map:match>


hth
Thomas


Am 21.05.2011 14:00, schrieb JeVeoy:
>
> First of all: thank you so much for helping me out, Steven&  Thomas!
>
> Then: I've tried my best to see if I could get a working example to run
> using either javax.imageio.ImageIO.write(RenderedImage, String,
> OutputStream) or AbstractReader.out, but to no luck. Googling didn't quite
> help either. I'm very sorry for my lack of knowledge... Hope you can forgive
> me.
>
> Pipeline for an image-reader is, as far as I know, defined in sitemap.xmap
> like this:
>
> <map:match pattern="*.jpg">
>    <map:read type="image" src="path/{1}.png" mime-type="image/png">
>    </map:read>
> </map:match>
>
> How can I make use of AbstractReader.out in this definition?


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


Mime
View raw message