views:

161

answers:

2

Hi everybody,

I'm just stuck with another programming problem. Within a JSP Web Page I have two urls. From two images, one is a Tiff and the other one is a PNG.

The one that is a PNG is like a stamp. The app functionality is to provide kind of a search mechanism for the Tiff images done and then provide the user with the option to print one of those images. BUT the image must be printed with the .PNG at bottom (it must not cover the original image).

One friend recommend me to generate a PDF with the two images inside one page, but I don't know how. Also, Im afraid that when doing that, will reduce the quality or bad-scale the image. Since those images are of very high historic values, the user must be able to print almost in the same original Tiff quality.

I have available a very good web server machine just for this app to work. So I don't mind about heavy use of resource. (Maybe it is not even necessary, but you know, when you ignore something is better to say all).

Than you very much in advance for your support.

+1  A: 

In order to send binary data you will need to use a servlet, but, you can take advantage of the Java Advanced Imaging API, http://java.sun.com/products/java-media/jai/forDevelopers/jaifaq.html and read in both images, then you can combine them and save them as a TIFF or PNG. The PNG is lossless so that should be fine, as it is easier to view in browsers.

I think that would be the simplest approach, though it has been years since I have used JAI.

James Black
+1  A: 

There are many ways to merge 2 images in JSP. You can use css or javascript to overlay 2 images. However, I assume your purpose is to protect the image. Then, you don't want do this in browser because the original image is still exposed.

You need to write a watermarking filter so all your images are stamped with that PNG. Many photo gallery software packages come with such filter.

Here is some code snippet to add watermark to an image,

    public static BufferedImage watermark(BufferedImage source, BufferedImage watermarkImage, Point position,
                    float transparency) {
            if (source == null)
                    return null;
            if (watermarkImage == null || position == null)
                    return source;
            Graphics2D g2d = (Graphics2D) source.getGraphics();
            AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transparency);
            g2d.setComposite(alpha);
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            g2d.drawImage(watermarkImage, position.x, position.y, watermarkImage.getWidth(), watermarkImage.getHeight(),
                            null);
            g2d.dispose();
            return source;
    }
ZZ Coder
Thank you very much ZZ Coder!
Sheldon