Add watermark to image

Mondeo

Centurion
Joined
Nov 10, 2006
Messages
128
Location
Sunny Lancashire
I'm building a site for a photographer who wants to sell his work online. To prevent people simply right clicking on the image and choosing save as we're going to "watermark" each image with the website address.

Is there any easy way to do this automatically using the image classes?

Thanks
 
There is no incredibly quick and easy way to do this, but with some effort you should be able to write a program to automate this process and perform batch-processing. You would have to use the Image class in conjunction with the Graphics class. The process would not really be reversible (you would naturally want to keep the originals) and there might be loss of image quality.

  • Assuming all the files are in the same folder, you would start by asking the user which folder the files are found in. I'm guessing that the images would be JPEGs. You can use the Directory.GetFiles method and specify a file pattern (i.e. "*.jpeg;*.jpg" but I'm not positive about the format) to get a string array containing filenames.
  • Loop through the files, opening them with the Bitmap constructor. Use the Graphics.FromImage function to create a Graphics object which can manipulate the image.
  • You can simply write some text to the image (Graphics.DrawString), use a pre-prepared semi-transparent image (Graphics.DrawImage), or use a pre-prepared but not semi-transparent image and use a color matrix to render the image semi-transparent.
  • After watermarking the image, save it. To optimize image quality and file size, you will probably want to enumerate image saving codecs to find the JPEG codec, with which you can specify the image quality (I can help you with this).
  • Dispose of the image and Graphics objects.
  • Repeat.

Hope that helps, and I'll be glad to help out if you hit some bumps along the way.
 
Back
Top