Script to sepia tone and watermark images in a folder
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

What I want: A script to watermark and sepia-tone all the .jpegs in a folder from the command line.

I have a folder with many jpegs I want to sepia-tone and watermark in one fell swoop. Please make me a shell script or ruby program that does that to every .jpeg in a given directory.

Specifications:

  • Parameters (4): folder directory, sepia tone intensity, watermark text, opacity of watermark text.
  • Please use the latest release of ImageMagick. I think this can probably be done with a long ImageMagick command, but please wrap the command in a shell or ruby script to make it more usable.
  • Should not recursively open folders- should just convert photos in the top-level one.
  • Should disregard non-jpegs
  • The small watermark should appear in the bottom right in 14px in Arial, with a small margin
  • Should output same dimensions as original
  • Program should output the new files in the same directory in a folder called 'sepia'.
  • New files should have "_sepia" appended to their names

Let me know if you have any questions before you get started! Cheers.

Would using automator work for you? It seems way easier to do it that way.
alex almost 8 years ago
Yep, automator is fine. Thanks.
bevan almost 8 years ago
awarded to minitech

Crowdsource coding tasks.

1 Solution


#!/bin/bash

if [ $# -ne 4 ]; then
    echo "Expected exactly 4 arguments.
Usage: sepia <folder-path> <sepia-intensity> <text> <watermark-opacity>
Example: ./sepia.bash my_images 70% \"A copyright\" 0.6"
    exit 1
fi

if [ ! -d "$1/sepia" ]; then
    if ! mkdir "$1/sepia"; then
        echo "Failed to create directory $1/sepia."
        exit 1
    fi
fi

for f in "$1"/*.jp*g; do
    base=$(basename "$f")
    output="$1/sepia/${base%.*}_sepia.jpeg"

    if ! echo "$f" | grep _sepia > /dev/null; then
        if convert "$f" -sepia-tone $2 -font Arial -pointsize 14 -draw "gravity southeast fill black fill-opacity $4 text 10, 10 '$3'" "$output"; then
            echo "Converted $f."
        else
            echo "Failed to convert $f"'!'
        fi
    fi
done

Today I learned bash scripting is hard! And make sure to chmod +x sepia.bash.

Sepia-licious! Thanks!
bevan almost 8 years ago