Summary

This page separates out the task of adding a watermark to a photo from the longer Perl image manipulation page. There is also a work-around if you are having trouble adding a watermark to an image that is already rotated. Here is the way my watermark looks:

watermark pic

Procedure

  • Make sure you have the program Image Magick installed. Search your package manager (like Synaptic) or use

    me@myhost$ sudo apt-get install imagemagick

  • Copy and paste the contents of this script using a plain text editor (not Word processor)

    #!/usr/bin/perl -w
    #2004-10 Kim Briggs
    #Abbreviated script to only put marker in upper left of pictures

    #Load all jpgs into an array. Remove trailing line feed.
    @pix = `ls *.jpg *.JPG`;

    foreach $pix (@pix) {
    chomp $pix;

    # Annotate the image with a web address. Upper left always works.
    `convert -fill black -draw 'roundRectangle 10,10 160,32 5,5' $pix $pix`;
    `convert -font Helvetica -fill white -pointsize 20 -draw 'text 15,27 " WATERMARK_TEXT "' $pix $pix`;

    #Print this out to have something to watch.
    $width = `identify -format "%w" $pix`; chomp $width;
    $height = `identify -format "%h" $pix`; chomp $height;
    print "Photo $pix size is ", $width, " by ", $height, " pixels.\n";
    }

  • Place the text file in a directory with ONLY COPIES of JPG photos you want watermarked, make sure the file it executable and name it with a ".pl" extension. You can do this in a file browser by right-clicking the file and selecting "Properties". Click on the Permissions TAB and check the box that says "Allow executing file as program".

  • In the default file browser for Ubuntu linux, you can double click the executable file and choose "Run in Terminal". If you are not given a choice, the option can be set in the file browser properties window.

  • Alternatively, you can use a terminal and browse to the needed folder and execute the file. If you named the file "watermark.pl", then it would look like this ("./") are instructions to start in the current directory.

    me@myhost$ ./watermark.pl

  • Experiment with the watermark text and the size of the box. You can alter the font, pointsize (font size), shape, etc. You will most likely also have to alter the total size. The first two numbers are the upper-left and lower-right points of the full sized shape. You will probably need LOTS of COPIES of the photos you are experimenting with.

  • Extra Step for Rotated Photos

    Cameras and phones have become so smart that they can tell when the camera has been rotated and mark this fact in the EXIF metadata of digital photos. This makes viewing them easier, but it messes up the reference point (0,0) when drawing the watermark. I found that I can get rid of this behavior by using the program gthumb to physically rotate the file. Presumably, this resets the zero to the upper-left point.

    Open gthumb and browse to the photos you want to physically rotate. You can use Ctrl+Click to select multiple file, or use your mouse to click and draw a box through your selection if you have them together in one directory. Click on the Tools icon in the upper right (looks like a wrench) and choose "Rotate Physically". The pictures are saved with a new zero reference and this method can be used to apply a watermark.

    gthumb rotate