Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Watermarks Examples?

 
Mike London
Ranch Hand
Posts: 1190
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1190
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mike London
Ranch Hand
Posts: 1190
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic