*
The moose likes Java in General and the fly likes Watermarks Examples? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Watermarks Examples?" Watch "Watermarks Examples?" New topic
Author

Watermarks Examples?

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
I'm trying to write some code that will programmatically paste some copyright text across a .JPG file that will reside on a web server.
I think this is called a watermark, but haven't found anyplace where there is a good sample program.
The Java 2D API graphics book didn't have an example on this.
Does anybody know a good source or book that has information on watermarking?
Maybe watermark is the wrong term, but I want to put a Copyright notice or something on a JPG before the "un-watermarked" one is purchased.
Thanks for any replies and ideas!
- Mike
Bill Cey
Greenhorn

Joined: Mar 22, 2003
Posts: 5
two thoughts. 1) can't you add code in your jsp which will draw over the jpeg or gif? i am sure there has to be some class in awt or swing that will do that. look at the paint methods. 2)why not load the gif or jpeg into photoshop and add it that way, then save it as a second jpeg, like you would have something.jpeg as the original and something2.jpeg, then write code in the jsp which gives the 2.jpeg to everyone but the original only to those who have purchased access.
just two ideas.
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
Thanks Bill for your reply.
Yes, you're right, there has to be code...somewhere that does it. I was hoping to find an example somebody had written.
The reason I don't want to use a program like Photoshop is that, unless there's an API interface, I'd be _manually_ doing hundreds of JPGs every day. Not much fun.
Thanks again.
-- Mike
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Mike,
Imaging is not my strongest suit, but it seems to me that you could create a BufferedImage of your jpegs, and call getWritableTile(int tileX, int tileY) which returns a WritableRaster and then overlay your copyright info using the various set methods there. It would involve some reasonably complex calculations and imaging techniques like XORing the copyright banner pixels into the raster but I think it could be done. Finally you could write the results to File, ImageOutputStream or OutputStream with an ImageIO.
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
Thanks for your reply.
Since on-line examples seem hard to come by, I've ordered a book on the 2D JAVA API and will delve into that.
Looks like I'm in for some "fun" learning.
-- Mike
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Mike,
Take a look at this (over simplified) example:

Now that doesn't really produce a Watermark, it just writes the text over the image. You should be able to create a true Watermark effect with a call to Graphics2D.setComposite() before drawing the text. As I said, I am no imaging expert so I'm not sure which compositing rule to use. Just take a look at the API docs on java.awt.AlphaComposite. To make this more generic, you will also probably need to use a java.awt.font.TextLayout to actually draw the text onto the image based on the dimensions of the image.
Michael Morris
[ March 26, 2003: Message edited by: Michael Morris ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Watermarks Examples?
 
Similar Threads
watermark in my webpage
Where do you live?
WA #1.....word association
Please help me with this. How do I get this effect?
Watermark image on pdf