MyRaspberryAndMe

Tinkering with Raspberry (and other things)

Something completely different

It is summer in Germany and so I am spending less time inside and some more time outside. Not very nerdy, but healthy. And it gives me the time to enjoy my other hobby, apart from tinkering stuff: photography. I started about 30 years ago with a Canon AE1 that I bought in used condition. It lay unused at my parents’ house for nearly 10 years and (Hooray) one week ago found its way to me again. And I am extremely happy, because it still works fine and has no visible signs of its age. It does not even have the famous “Canon shutter squeal“, so many of its brothers and sisters are suffering.

But this is not about my analogue cameras, this is about a little helper I programmed to help me keep my digital and digitized images in order.I keep all my images on a NAS storage system, ordered by year/month and a short description. That makes searching easy and I do have easy access to it. Of course, the images are imported to iPhoto, which is completely sufficient for my needs. I do not need Lightroom or Aperture or any other software. A long time ago I decided to take my images in JPG format, not as RAW images. I simply do not have the time or the passion for long hours of editing work.

So I needed a tool to rename my images automatically to something like “yyyymmdd-hhmmss-nn.jpg” based on the EXIF data. This is standard for most photo software. I do this with a batch job and I am using the famous “exiftool“. With the rise of social media and more and more friends moving to distant places (hence the need to share images) I needed more and decided to program a tool that will

  • rename the JPG files
  • scale them to a given width/height
  • converts the filenames to lowercase
  • rotates the images according to EXIF data
  • can add a signature/info to the image
  • can clear all EXIF data for privacy reasons
  • add a Copyright tag to the EXIF data

All this is done by a combination of the above mentioned Exiftool and “Imagemagick“. Below is an example panorama image that was taken from this point with my beloved Fuji X100 camera.

The complete black banner at the bottom is generated from the script. The information on shutter speed and aperture is taken from the EXIF information. I decided to “add” the banner to the image and not overlay it.

Here’s the script. It has to be started in the directory the original pictures are in, creates a directory to write to and batch processes all JOG files it finds in the current directory.

!/bin/bash

# Prepare images for publishing in photoblog.
# Images get renamed, resized, stripped of private EXIF infos and
# a copyright notive is added.
# Superimposed on the picture get aperture, shutter and ISO values
# and the filename for fast identification.
# needs imagemagick and exiftools

# this script can be freely used if credit is given
#
# Author: mypiandme
#         myraspberryandme.wordpress.com

# Arguments
#
# -l           : convert filename to lowercase
# -n           : rename according to datetime stamp
# -r           : autorotate (lossless) according to EXIF
# -s XxY       : resize images to X,Y preserving ratio
# -a           : automagically add signature (copyright - filename - some EXIF data)
# -x           : strip all EXIF data (privacy)
# -c           : add Copyright field to metadata
# -d name      : directory to write altered images to

LOWERCASE=1
RENAME=
ROTATE=
RESIZE=
ADDSIG=
STRIP=
COPY=
DIR="small"
SIGNATURE=""
COPYRIGHT=" (c) by mypiandme "
EXT=

# source export_paths.sh

while getopts "nrs:axcd:" OPTION
do
    case $OPTION in
        n)
            RENAME=1
            ;;
        r)
            ROTATE=1
            ;;
        s)
            RESIZE=$OPTARG
            ;;
        a)
            ADDSIG=1
            ;;
        x)
            STRIP=1
            ;;
        c)
            COPY=1
            ;;
        d)
            DIR=$OPTARG
            ;;
    esac
done

if [ "$LOWERCASE" ]; then
    # make all lowercase if uppercase
    for f in *.JPG; do mv -v $f `echo $f | tr '[A-Z]' '[a-z]'`; done
fi
if [ "$RENAME" ]; then
    # and rename
    for i in *.jpg; do exiftool -d %Y%m%d-%H%M%S-%%.2c.%%e "-FileName<DateTimeOriginal" $i; done
fi

if [ "$DIR" == "small" ]; then
    echo "Using default directory ("$DIR") for altered images!"
fi
mkdir $DIR
# now batch
for i in *.jpg
do
echo 'START file '${i}

if [ "$ROTATE" ]; then
    # autorotate lossless
    convert -auto-orient $i $i
    echo 'Rotation done.'
fi
if [ "$RESIZE" ]; then
    # resize
    convert $i -resize ${RESIZE} ${DIR}/$i
    echo 'Resize done.'
fi
if [ "$ADDSIG" ]; then
    # get info
    APERTURE=`exiftool -aperture ${i}`
    SPEED=`exiftool -exposuretime ${i}`
    ISO=`exiftool -iso ${i}`
    SIGNATURE='f='${APERTURE##*: }'  t='${SPEED##*: }'  ISO='${ISO##*: }

    convert ${DIR}/$i -gravity south -background "#00000080" -splice 0x18 -font Courier \
        -gravity southeast -fill "#ffff00" -undercolor '#00000080' -annotate +2+2 "$SIGNATURE" \
         -gravity south -fill "#ffff00" -undercolor '#00000080' -annotate +2+2 "$i" \
        -gravity southwest -fill "#ffff00" -undercolor '#00000080' -pointsize 12  \
        -annotate +2+2 "$COPYRIGHT" \
         ${DIR}/$i
    echo 'Added annotations ('$SIGNATURE')'
fi
if [ "$STRIP" ]; then
    #strip all EXIF info
    exiftool -overwrite_original -all= ${DIR}/$i
    echo 'Stripped all EXIF data'
fi
if [ "$COPY" ]; then
    #add Copyright
    exiftool -overwrite_original -copyright="$COPYRIGHT" ${DIR}/$i
    echo 'Added copyright tag'
fi
done

Advertisements

Comments are closed.