Mikedowney.co.uk
What's New
Site Map

Diary
Astronomy
Bits N Bobs
Computing
Food And Drink
Links
Photography
Welcome


Recipe Collections
Recipe A Week 2013
Recipe A Week 2010
A-Z of Regional Cakes
Alphabet of Nations

Trying to prevent image theft 2: Watermarking images

Story location: Home / computing /
14/Apr/2008

Yesterday I mentioned using the .htaccess file with Apache to prevent people hot-linking images. That would only be a temporary solution, which would stop current hot-links from working. Any future image theft would involve people downloading images and re-uploading them somewhere else.

One way of stopping that is to add a watermark to each image. There are a lot of websites explaining how to do that manually in Photoshop or Gimp, but I needed a simple way of adding a watermark to several hundred images.

I had heard about Image Magick and thought it might have a way of doing it. There are instructions here explaining how to do it.

The images on my website are spread across a lot of directories, so I wrote a small perl script to watermark all the images in a directory (including subdirectories):

#!/usr/bin/perl
# use ImageMagick to add copyright watermark to images

use File::Find;
use strict;

my  = "jpg|png";    # file extensions to apply watermarks to
my /computing = "/images";      # directory holding the images
my  = "/copyright3.png";    # full path to watermark image

sub processFile{
    return if ($_ !~ /.*\.[]/);
    my  = ::name;

    `composite -dissolve 10% -tile  "" ""`;
}

find(\&processFile,/computing);

The /computing and `` variables should hold the full path for the directory and watermark file. You'll need to produce an image with a transparent background for the watermark.

Changing the 10% value gives a ligher or darker watermark, depending on how obvious you want it to be.