views:

321

answers:

5

I'm creating a website which requires the images in the site's Gallery to be watermarked. I'd prefer the watermark to get added programatically when the image gets uploaded to the application (via it's web interface) than to manually add it before we do the upload.

Are there any simple ways (perhaps an image library?) that will allow me to do this?

I'm building the site in Grails, so a Groovy or Java solution would be great.

+2  A: 

I'm not sure if copyright and your process allows but an alternative suggestion is to render the watermark when the images are displayed rather than altering the image on upload. This would allow you to change the watermark and have access to the raw image.

Dave Barker
Good point: don’t destroy the original. But you don’t want to superimpose the watermark on every download, you still want to do it when the image is uploaded.
Bombe
+1  A: 

I've been working on an Grails application that does a lot of image manipulation and we chose to call out to ImageMagick. There is an Image Tools plugin for Grails which might be suitable for simple watermarking, however we needed the extra power that IM provides.

Groovy's Process additions make it pretty easy to call out to IM and then parse the err/out streams. If I had time I'd release an IM plugin, but I don't sorry!

cheers

Lee

leebutts
+1 for ImageMagick. I've evaluated multiple approaches on image manipulation and found IM to be the best one (performance, stability, quality). There is also a wrapper library for Java: http://im4java.sourceforge.net/
Siegfried Puchbauer
It's kind of simple, so I'd rather avoid bringing in ImageMagick to do something I can do in < 10 LOC. But thanks for the idea.
Benny Hallett
+1  A: 

Create a BufferedImage. Draw the uploaded image to the BufferedImage and then draw the watermark to the BufferedImage.

camickr
+4  A: 

This is the code you want I think...

BufferedImage source = ...;
BufferedImage watermark = ...;
Graphics2D g = source.createGraphics();
g.drawImage(watermark, x, y, null);
g.dispose();
Martijn Courteaux
A: 

check this link link text

irshad