Watermarking the easy way

March 01, 2010 Morgan Image Library C# Snippet
This post will show how easy it is to do a bit of watermarking using the open source C# Image Library.

What we'll do
Watermarks can appear in many different ways. This sample will show how to create the following in just a couple of lines:

(Image above courtesy of Morgan over at Imaginations. Check out his site for some beautiful CG imagery.)

Step by step

Preparations
First of all, head over to http://code.google.com/p/imagelibrary/ and download the latest DLL (or source code if you want to compile it yourself).

Secondly, you'll need a watermark to apply to your images. Create a PNG image with very transparent layers in both black and white. The one I've created has black texts in a layer of 10% opacity as well as a white outline also with 10% opacity. (Please note that the watermark will be tiled, in other words used x * y times to cover the image you want to mark.)
This is my watermark.png (applied on a gray background):


Finally lets do some coding!
 Create a new project and add the C# Image library  you just downloaded (either the DLL or the project). Enter the following lines (in the appropriate place, depending of what type of project you're developing).
using Kaliko.ImageLibrary;

//...

// Open the image you want to watermark
KalikoImage image = new KalikoImage("c:\\MyImage.jpg");

// Apply your watermark PNG image
image.BlitFill("c:\\Watermark.png");

// Save new marked image as high-quality jpeg
image.SaveJPG("c:\\Marked.jpg", 99);

That wasn't so hard, was it? :) The C# Image library is developed to ease common graphical tasks as this.

Related posts: