Question

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.

Was it helpful?

Solution

This is the code you want I think...

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

OTHER TIPS

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.

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

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

If you are using grails, I think the easiest way to add a watermark or resize the image to use the burningimage plugin https://grails.org/plugin/burning-image

Its very easy to use and well documented. Find the documentation here: https://code.google.com/p/burningimage/

To the the watermark you simple have to do the following

burningImageService.doWith('path/to/my/file', 'path/to/output/dir')
               .execute {
                   it.watermark('path/to/watermark', ['top':10, 'bottom': 10])
                }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top