Am 19.05.2011 15:49, schrieb JeVeoy:
I'm using Cocoon 2.2Case I would like to merge 2 images in PNG format on the server (buffered image) and then send the result back as a stream. Thus NOT saving the image on the server. As an example you could have a nice background picture of a field. The field (background image) changes according to season (winter, spring etc). The user has the option to choose what kind of tree to display on the field. He/she can select from a wide range of fruit trees like olive, apple etc. One option is to save all possible combinations as unique images on the server. I want to avoid this since the total number of combinations could get very high. It could get really difficult to maintain changes to backgrounds and trees. I would prefer to have 4 background images and 1 image for every tree and combine these on the fly and present the result to the user without saving it on the server. Merge The merge itself is ok and works like a charm. Code written in Java uses java.awt.image.BufferedImage. Code // base path of the images File path = new File("C:/images"); // load source images BufferedImage image = ImageIO.read(new File(path, "background_summer.png")); BufferedImage overlay = ImageIO.read(new File(path, "tree_apple.png")); // create the new image, canvas size is the max of both image sizes int w = Math.max(image.getWidth(), overlay.getWidth()); int h = Math.max(image.getHeight(), overlay.getHeight()); BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); // paint both images, preserving the alpha channels Graphics g = combined.getGraphics(); g.drawImage(image, 0, 0, null); g.drawImage(overlay, 0, 0, null); // Save as new image ImageIO.write(combined, "PNG", new File(path, "combined.png")); Using PNG format on image enable result with transparency. And here comes the challenge. Instead of saving image to disc and then referring to it in sitemap.xmap I would like to return the stream.
You can use javax.imageio.ImageIO.write(RenderedImage, String, OutputStream) to write directly into an OutputStream. You just need to get the OutputStream from the original HTTP request. HTH, Steven
As far as my understanding goes I would have to catch the request in sitemap.xmap (map:match pattern="getTree.*") and then call flow script using map:call function with map:parameter. In the flow-function I would get the parameter (in this case, the type of tree to display) and call the java-function as written in the above snippet. But how do I return a stream as a PNG image to the browser using sitemap.xmap?
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
