Single And Batch Watermarking Of JPEG Images

How To Add A Watermark To JPEG Images

Watermark Example Image

This section applies to both Windows and Linux.

Here's how I added the watermark logo onto my sample image pages using ImageMagick's Linux commands. (ImageMagick and GIMP are both also available for Windows platforms.) As an example, click on the sample images and look in the top right corner on the Nokia N95 Sample Images page. You'll see in 50% transparency in the top right of each image.

Here's how you do it.

First of all, if you haven't already, install ImageMagick. It's the composite command which is part of ImageMagick we need, which overlays one image with another.

Make a watermark logo. I use GIMP for graphics editing, which is excellent, and free. Make the watermark image fairly small, and give it a transparent background. Also, make the text white and give it a black blur behind, or black with a white blur, so it will show up and be readable equally well on any colour background image. Make sure you save it in a format that supports transparency, preferably PNG format.

Watermark Image

Here's my watermark file. It's actually got a transparent background, but I've coloured the transparent area with blue, just to illustrate the white blur around the text.

If you're applying the watermark to a large photo that needs re-sizing for the web, make sure you re-size the photo first, then add the watermark.

Now, place the watermark and image file in a directory somewhere and use the following command:

composite -gravity northeast -quality 90 -dissolve 50 watermark.png image.jpg newimage.jpg

The gravity option means the image and the watermark will be combined with corresponding top-right corners. The quality option specifies the resulting quality for the output image, in this case 90% jpeg. The dissolve option specifies, in this example, 50% transparency. Lower values will make the watermark appear fainter.

For other options on the composite command, see the composite man page.


Adding Watermark To A Batch Of Files

This section applies to Linux only.

The next step is to add the watermark to a batch of images. If you've got loads of jpegs to watermark, it might be worth trying this. The following example uses the same composite command as in the example above, but uses find to apply the command once for each file. Here, I'm modifying each image and outputting it with the same name overwriting each original image. I've done this because it makes the command easier, so make sure you backup all the jpegs in the current directory before doing this so you can restore them if you're not happy with the result.

In this example, find will get each file in the current directory ending in jpg. Obviously, if you're working with png or gif files, replace this bit. Next, -type f specifies to only look for regular files, not directories or links or whatever. Then, for each of these files, it will execute the command following -exec. It replaces the {} with the filename, so I'm just using the same name for input and output files.

find . -name "*jpg" -type f -exec composite -gravity northeast -quality 90 -dissolve 50 watermark.png {} {} \;

Again, don't forget to backup your images before running this!

I hope this was of some help to you.

Powered by WebRing.

Page Updated 16/04/09