Automatically Geotagging your Gallery

Tags from Blakepics

Automatically add tags to Gallery

As always, an imminent holiday has inspired me to update the entire system behind geotagging my photos.  Likewise, needing to plan said holiday has given me the opportunity to procrastinate and do something else instead.


  • A repository I can drop files created by the Genie BGT-31 GPS tracker.
  • Automatically convert the tracks into GPX format.
  • Automatically stamp any photos within Blakepics with their longitude / latitude values into the EXIF information.
  • Use that EXIF information to populate the database for the Gallery2 maps module.
  • Use geonames to get some basic tags, and automatically add those to the tags database.

I can happily report all of the above is happily running on a schedule on the Blakepics server.   Whilst I realise a lot of these options aren’t particularly available on a shared hosting server, I’m going to talk about them anyway.

A small disclaimer

Be under no illusion, a lot of these scripts are hacked together with no thought given to scalability, stability, or re-use.  They’d be a lot better off as a proper Gallery2 module to be honest – and hopefully someone will beat me to it in making that a reality.  However, for the time being – this is all provided as-is 🙂

NMEA repository

The repository is quite simple with an SFTP server running (sshd for example), and FileZilla on the client

Convert the tracks to GPX

  1. Install the rather excellent gpsbabel.
    yum install gpsbabel
  2. Run this perl script to combine all your nmea tracks to create a single gpx file.

Stamp the photos

  1. Get the gpsPhoto perl script.  You might find you need to install some perl modules:
    perl -eshell -MCPAN
    install modulename
  2. Use this script to find any matching photos from your Gallery, and tag them.  Note that I limit them to only photos I’ve uploaded myself, as I don’t want to go messing around with other peoples (and they were probably not at the same location anyway)

Fill the Gallery2 maps module with the EXIF data

There’s a maintenance task to use the EXIF data to power the maps module of Gallery2, so using Roel Broersma’s excellent script to run the maintenance tasks, these can be scheduled with the extra line:

wget --quiet --output-document=/dev/null --cookies=on --load-cookies $TMP_PATH/myg2cookies "$G2_URL/main.php?g2_controller=core.AdminMaintenance&g2_form%5Baction%5D%5BrunTask%5D=1&g2_taskId=PopulateGPSEXIFInfos&g2_authToken=$AUTHTOKEN"

Give some meaning to your location data with geonames

Geonames provides a reverse-lookup to get some more human readable descriptions of your photos.  So I use this to put in the country, region and town data into my Gallery.  You can go a bit further and get details of nearby landmarks from Wikipedia to add if you like, but i don’t find it too useful for my purposes.

  1. You’ll need some more perl modules
    perl -eshell -MCPAN
    install Image::ExifTool;
    install Image::ExifTool::Location;
    install Geo::GeoNames;
    install Data::Dumper;
  2. Get my perl script, which is actually a combination of all the previous scripts.  This will query the web service, and update your tags.

It all sounds very complicated…

Well, yes.  My aim isn’t to create the easiest system to set-up, it’s to create the easiest system to use.  Uploading a single NMEA track list now causes all of the above to happen automatically.  That said, I recognise that it’s not for the faint-hearted.

So why not try one of these easier solutions:

What next?

Add all of these scripts mentioned above to a cron task, and forget all about it.  You can probably combine the whole lot into a single job (I wanted to keep them separate, so some could be run nightly, and others weekly or monthly).

Hopefully this is the humble beginnings of a more efficient and elegant solution.  For now I’m at least getting a lot more data into and out of my photos

Do let me know if you make any improvements, or have any ideas for viable new features – I’d be interested to hear from you.

Tags: , , , , ,

Leave a Reply?