• Automate your Watermarking Workflow

    by  • September 3, 2010 • Photography, Programming

    Recently, I started to put up more photos on Flickr. Before publishing my photos, I usually watermark them. For a small number of uploads, it was sanely possible to add watermarks using photo editors manually. However, it gets a bit tedious when attempting to watermark, catalogue, upload, tag etc. tens of photos at one go.

    To make my life easier, I used a simple ImageMagick workflow based on this tutorial to quickly watermark a bunch of images files. At first, I had this post-processing job running as a Bash script in a Linux Virtual Machine, but it soon became too troublesome to shuffle files between the two operating systems. PowerShell comes pre-installed with Windows 7, so that was a great option for creating a script to process multiple files.

    So here’s what’s involved when I process files to be posted on Flickr:

    1. Create a watermark image file. I made this a transparent image and saved it in PNG format. Place the watermark file in a your working directory (e.g. c:\myworkflow).
    2. Next, create the directories for your source image files (e.g. c:\myworkflow\source) and copy your photos into this sub-directory. Make any edits here before performing the watermarking process.
    3. Create two more directories for the ImageMagick to save the resized and watermarked files (e.g. c:\myworkflow\flickr\resized and c:\myworkflow\flickr\watermarked respectively).
    4. Create a temp directory if preferred (e.g. c:\myworkflow\temp). Piping processes worked fine in Linux, but I did not have much success in Windows. Hence, intermediate outputs are written to the file system instead.
    5. Place this script in the working directory and edit the variables if necessary.
    6. The $filePattern variable is useful if you would like to iterate your source files selectively. I sometimes prefix my photos with a set number. Photos within sets were usually taken in the same year. I can then use the set numbers to watermark the image with the matching copyright year.

    The code:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    $srcDir = "C:\myworkflow\source"
    $resizedDir = "C:\myworkflow\flickr\resized"
    $watermarkFile = "C:\myworkflow\watermark_image.png"
    $watermarkedDir = "C:\myworkflow\flickr\watermarked"
    $tempDir = "C:\myworkflow\temp"
    $filePattern = "*"
     
    foreach ($f in ls "$srcdir\$filePattern") {
        $f = split-path $f -Leaf
        Write-Host "Processing: $f"
        convert -resize 800x800 "$srcDir\$f" "$resizedDir\$f"
        convert $watermarkFile -fill grey60 -colorize 30 "$tempDir\temp.miff"
        composite -dissolve 50 -gravity south "$tempDir\temp.miff" "$resizedDir\$f" "$watermarkedDir\$f"
    }

    The parameters for ImageMagick commands may not be optimal for all scenarios. Change them if necessary. If you have any feedback or suggestion for improvement, please feel free to give me a shout.

    Share

    About