Injecting Data into Scanned Vintage Photos

In a previous post, entitled Vintage Photo Scanning – A Journey of Discovery, I shared my experiences while digitising my parent’s entire vintage photo collection.

As part of that pet project, I also took the liberty of digitally injecting some of the precious data I had learned about them (i.e. when and where the photos were taken, and who was in them) into the photo files themselves, so that it would be preserved forever along with the photo is pertained to. This article explains how I did that.

Quick Recap

My starting point was a collection of around 750 digital images, arranged into a series of folders and subdirectories, and named in accordance with the following convention:

<Date>~<Title>~<People>~<Location>.jpg

So the task at hand was how to programmatically (and thus, automatically) inject data into each of these files, starting over if required, so that sorting them or importing them into photo management software later becomes much easier.

Ready, Steady, Bash!

In order to process many files at a time, you’re going to need to do a little programming. My favourite language for this sort of stuff is Bash, so expect to see plenty of snippets written in Bash from here on. I am also going to assume that you are running this on a Unix/Linux-based system (sorry, Mr. Gates).

Setup

While each photo will have a different date, title, list of people and location, there are some other pieces of data you like to store within them (while you’re at it), which you (or your grandchildren) may be glad of later on. To this end, let’s set up some assumptions and common fields.

Default Data

If you only know the year of a photo, you’ll need to make some assumptions about the month and day:

DEFAULT_MONTH="06"
DEFAULT_DAY="01"
DEFAULT_LOCATION="-"

Reusable File Locations

Define the location of exiftool utility or any other programs you’re using (if they are located in a non-standard part of your system), along with any other temporary files you’ll be creating:

EXIFTOOL=/usr/local/bin/exiftool
CSVFILE=$(dirname "$0")/photos.csv
GPSFILE=$(dirname "$0")/gps.txt
GPS_COORDS=$(dirname "$0")/gps-coords.txt
PHOTO_FILES=/tmp/photo-files.txt
PHOTO_DESC=/tmp/photo-description.txt

Common Metadata

Most photo files support other types of metadata including the make/model of camera used, the applicable copyright statement and of the owner of the files. If you wish to use these, you could define their values in some variables that can be used (for each file) later on:

EXIF_MAKE="HP"
EXIF_MODEL="HP Deskjet M4500"
EXIF_COPYRIGHT="Copyright (c) 2014, James Mernin"
EXIF_OWNER="James Mernin"

Data Injection

List, Iterate & Extract

Firstly, compile a list of the files you wish to process:

find "$IMAGE_DIR" -name "*.jpg" > $PHOTO_FILES

Now iterate over that list, processing one file at a time:

while read line; do
 # See below for what to do...
done < "$PHOTO_FILES"

Now split the input line to extract the 4 field of data:

BASENAME=`basename "$line" .jpg`
ID_DATE=`echo $BASENAME|cut -d"~" -f1`
ID_TITLE=`echo $BASENAME|cut -d"~" -f2`
ID_PEOPLE=`echo $BASENAME|cut -d"~" -f3`
ID_LOCATION=`echo $BASENAME|cut -d"~" -f4`

Prepare Date & Title

Prepare a suitable value for Year, Month and Day (taking into account the month and day maybe unknown):

DATE_Y=`echo $ID_DATE|cut -d"-" -f1`
DATE_M=`echo $ID_DATE|cut -d"-" -f2`
if [ -z "$DATE_M" ] || [ "$DATE_M" = "$DATE_Y" ]; then DATE_M=$DEFAULT_MONTH; fi
DATE_D=`echo $ID_DATE|cut -d"-" -f3`
if [ -z "$DATE_D" ] || [ "$DATE_D" = "$DATE_Y" ]; then DATE_D=$DEFAULT_DAY; fi

It’s possible the title of some photos may contain a numbered prefix in order to separate multiple photos taken at the same event (e.g. 01-School Concert, 02-School Concert). This can be handled as follows:

TITLE=$ID_TITLE
TITLE_ORDER=`echo $ID_TITLE|cut -d"-" -f1`
if [ -n "$TITLE_ORDER" ]; then
 if [ $TITLE_ORDER -eq $TITLE_ORDER ] 2>/dev/null; then TITLE=`echo $ID_TITLE|cut -d"-" -f2-`; fi
fi

Location Processing

This is a somewhat complex process but essential boils down to trying to determine the GPS coordinates for the location of each photo. This is because most photo file only support the GPS coordinates inside their metadata. I have used the Google Maps APIs for this step with an assumption that you get an exact match first time. You can, of course, complete this step as a separate exercise beforehand and store the results of that in a separate file to be used as input here.

In any case, the following snippet will attempt to fetch the GPS coordinates for the location of the given photo. Pardon also the crude use of Python for post-processing of the JSON data returned by the Google Maps APIs.

ENCODED_LOCATION=`python -c "import urllib; print urllib.quote(\"$ID_LOCATION\");"`
GPSDATA=`curl -s "http://maps.google.com/maps/api/geocode/json?address=$ENCODED_LOCATION&sensor=false"`
NUM_RESULTS=`echo $GPSDATA|python -c "import json; import sys; data=json.load(sys.stdin); print len(data['results'])"`
if [ $NUM_RESULTS -eq 0 ]; then
 GPS_LAT=0
 GPS_LNG=0
else 
 GPS_LAT=`echo $GPSDATA|python -c "import json; import sys; data=json.load(sys.stdin); print data['results'][0]['geometry']['location']['lat']"`
 GPS_LNG=`echo $GPSDATA|python -c "import json; import sys; data=json.load(sys.stdin); print data['results'][0]['geometry']['location']['lng']"`
fi

Convert any negative Latitude and Longitude values to North/South or West/East so that your coordinates end up in the correct hemisphere and on the correct side Greenwich, London:

if [ "`echo $GPS_LAT|cut -c1`" = "-" ]; then GPS_LAT_REF=South; else GPS_LAT_REF=North; fi
if [ "`echo $GPS_LNG|cut -c1`" = "-" ]; then GPS_LNG_REF=West; else GPS_LNG_REF=East; fi

Inject Data

You now have all the data you need to prepare the exiftool command:

EXIF_DATE="${DATE_Y}:${DATE_M}:${DATE_D} 12:00:00"
echo "Title: $TITLE" > $PHOTO_DESC
echo "People: $ID_PEOPLE" >> $PHOTO_DESC
echo "Location: $ID_LOCATION" >> $PHOTO_DESC

if [ -n "$ID_LOCATION" ]; then
 $EXIFTOOL -overwrite_original \
  -Make="$EXIF_MAKE" -Model="$EXIF_MODEL" -Credit="$EXIF_CREDIT" -Copyright="$EXIF_COPYRIGHT" -Owner="$EXIF_OWNER" \
  -FileSource="Reflection Print Scanner" -Title="$TITLE" -XMP-iptcExt:PersonInImage="$ID_PEOPLE" "-Description<=$PHOTO_DESC" \
  -AllDates="$EXIF_DATE" -DateTimeOriginal="$EXIF_DATE" -FileModifyDate="$EXIF_DATE" \
  -GPSLatitude=$GPS_LAT -GPSLongitude=$GPS_LNG -GPSLatitudeRef=$GPS_LAT_REF -GPSLongitudeRef=$GPS_LNG_REF \
  "$line"
 else
  $EXIFTOOL -overwrite_original \
   -Make="$EXIF_MAKE" -Model="$EXIF_MODEL" -Credit="$EXIF_CREDIT" -Copyright="$EXIF_COPYRIGHT" -Owner="$EXIF_OWNER" \
   -FileSource="Reflection Print Scanner" -Title="$TITLE" -XMP-iptcExt:PersonInImage="$ID_PEOPLE" "-Description<=$PHOTO_DESC" \
   -AllDates="$EXIF_DATE" -DateTimeOriginal="$EXIF_DATE" -FileModifyDate="$EXIF_DATE" \
   "$line"
 fi

Cross your fingers and hope for the best!

Apple iPhoto Integration

Personally, I manage my portfolio of personal photographs using Apple iPhoto so I wanted to import these scanned photos there too. And so the Data Injection measures above I took above simplified this process greatly (especially the Date and Location fields which iPhoto understands natively).

While I did then go on to use iPhoto’s facial recognition features and manually tag each of the people in the photographs (adding several weeks to my project), the metadata injected into the files helped make this a lot easier (as it was visible in the information panel displayed beside each photo) in iPhoto.

Return on Investment

Timescales

In all, this entire project took almost 9 months to complete (with an investment of 2-3 hours per evening, 1-2 nights per week). The oldest photograph I scanned was from 1927 and the most precious one was one from my early childhood holding a teddy bear that my own children now play with.

Benefits

The total number of photos processed was somewhere in the region of 750. And while that may appear to be a very long time for relatively few photographs, the return on investment is likely to last for many, many multiples of that time.

Upon Reflection

I’ve also been asked a few times since then, “Would I do it again?”, to which the answer is an emphatic “Yes!” as the rewards will last far longer than I could ever have spent doing the work.

However, when asked, “Could I do it again for someone else?”, that has to be a “No”. And not because I would not have the time or the energy, but simply because I would not have the same level of emotional attachment to the subject matter (either the people or the occasions in the photos) and I believe that this would ultimately be reflected in the overall outcome. So hopefully these notes will help others to take on the same journey with their own families.

Free Mobile apps for LEGO fans

In my endless pursuit of different ways to enjoy LEGO products, I found the following free mobile apps in the Android app store (a.k.a. Google Play).

  • LEGO Creationary – Excellent series of build and guess games, created by the LEGO Group themselves. A bit heavyweight in terms of performance though.
  • myBrickset: LEGO Set Guide – Allows you to search for LEGO sets by number and create a catalog of the ones you own (or want to own).
  • LEGO Instructions – Lots of simple LEGO sets for younger children, complete with interactive step-by-step instructions.
  • LEGO Scans – Quickly peruse through over 4,000 LEGO sets by name or theme (but no instructions included though).
  • LEGO Minifig Collector – Search and browse through the full series of Minifigure collections. You can also tell the app which ones you have and it’ll then tell you which ones you’re missing (a potentially expensive feature).
  • Lego Mini Figure Identifier – Very clever app for helping you identify which minifigure in inside the package before you buys it. However, LEGO have made it a lot harder to use this app since Minifigure Series 5 onwards so bring a microscope with you if you intend to use this app.
There are loads more, some of which are just mobile games inspired by the LEGO brand and others are for much younger children or for specific LEGO sets.

Food & Wine Tasting Evening

If you’re around the Waterford area on Wednesday, 14 December 2011, why not come along to the annual Food & Wine Tasting Evening at the Grand Hotel and sample a wide variety of beers, wine and local food – all for just €8.

This is a fundraiser in aid of two local schools (Gaelscoil Philib Barún and Holy Cross National School) and is sponsored by Hickson’s Centra, Tramore.

Remember: Grand Hotel, Tramore – Wednesday, 14 December 2011 – 7:30pm – 10pm – €8 per person

Hope to see you there.

Over 915 million ways to combine just 6 LEGO bricks

It’s been a while since I’ve posted anything about my favourite toy, LEGO, so I thought I’d correct that with a crazy LEGO fact that stuck in my mind this weekend while watching National Geographic’s special MegaFactories: LEGO. So here it is:

The number of unique ways you can combine 6 classic (2×4 stud) LEGO bricks of the same colour is an incredible 915,103,765

That’s over 915 million different ways! So, if like me, you had to find out how they came up with this number, there’s a great story behind it here, along with some great numbers regarding combining of larger numbers of bricks.

Other great facts from this same programme were:

  • Over 50% of LEGO’s entire annual sales take place in the 2 months before Christmas each year
  • The LEGO factory in Billund, Denmark is technically the largest manufacturer of tyres in the world (great table quiz question!)
  • Worldwide, 7 LEGO products are sold every second

1848 Tricolor Celebration in Waterford, Ireland

Some friends of mine are part of a group that are organising a formal celebration of the history and origin of Ireland’s national flag – more commonly known as the Tricolor – in the city where it was first unveiled – Waterford.

Jonathan Brazil has also written an excellent piece that introduces the planned celebrations far more eloquently than I ever could, so feel free to read his post too.

For more information check out http://www.1848tricolour.com and join in the festivities.

Elizabeth “Lily” Mernin and Michael Collins

I’m often quizzed about a lady called Lily Mernin who features in many historical journals relating to the Irish Easter Rising of 1916 and to Irish independence generally. It seems that she worked as a spy for Michael Collins back in the early 1920’s (perhaps earlier).

The Irish Times printed another article about her recently, which is actually a repeat of a similar article from 1996 (around the time that Neil Jordan’s movie of the same name was released).

In terms of her relationship to the current generation of Mernins (based out of Villierstown, Co. Waterford), it seems that she was a first cousin of my Grandfather, Edmund (Neddie) Mernin. She (and her heroic exploits) is often cited when the nationalism of my family name comes into question (mostly in jest, I should add). And indeed while Mernin isn’t generally considered a very Irish name, Lily certainly was.

Reference

I’m often quizzed about a “Lily Mernin” who worked as a spy for Michael Collins. This article is a repeat of a similar one from around the the Neil Jordan’s movie of the same name was released some years ago.

Of course my family’s patriotism is also often question (Mernin isn’t a very Irish name) but this article puts paid to that theory I think!

Dublin to Waterford Motorway now open

Today, Thursday 9th September 2010 marks a very significant day for anyone living in the Waterford (or South Kilkenny area) of Ireland. Finally, after more years than I care to remember, we can celebrate the reality of a fully uninterrupted motorway from Waterford to Dublin.

It may seem trivial (and even archaic) to some readers, but take it from me, this is a really big deal in this part of the country and so very long overdue. At long last, the Sunny South East will be a perfectly manageable (and comfortable) distance from our capital city, and should make day-trips, holidays and visiting friends and family and much less stressful experience.

Source: RTÉ News

Irish Times Crossword Compiler dies ages 92

I have always been an admirer of the Crosaire Crossword in The Irish Times but very rarely deciphered more than a handful of the clues, and mostly opted for the Simplex version instead. I was saddened to learn of the recent death of the man behind the Crosaire, Derek Crozier, who had been compiling it since 1943. He died on Saturday last (3 April 2010) at his some in Zimbabwe, at an impressive age of 92. May he rest in peace.

Source: RTÉ News

Average Car Mileage in Ireland

I have often wondered where people get their figures from when quoting average mileage on cars. Personally, I’ve had a figure of 10,000 miles per year floating around in my head for as long as I can remember, and think I originally got this figure from my father.

However, whilst perusing through the second hand car market recently, the issue of average mileage came up again but this time in relation to Petrol versus Diesel cars. To be honest, I’d never really given much thought to the fact that the average figure might different depending on the fuel type. However, according a Private Motoring Energy Usage report by the Sustainable Energy Authority of Ireland in 2005, there is indeed a difference (of around 50%) between the two:

  • Average annual mileage of all cars: 16,894 kilometres (10,498 miles)
  • Average annual mileage of Petrol cars: 15,969 kilometres (9,923 miles)
  • Average annual mileage of Diesel cars: 23,817 kilometres (14,799 miles)

Whilst the report is now 5 years old, I can’t image the relative figures for 2010 are that different. It also looks like my father was not too far off the mark either!