Automatically Geotagging your Gallery

Sunday, November 16th, 2008
Tags from Blakepics

Automatically add geonames.org 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.

Wishlist

  • 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 convert-to-gpx.pl.txt 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 geocode-photos.pl.txt 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 write-geoname-tags.pl.txt 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.

Some Blakepics caption stats

Sunday, January 20th, 2008

“Nothing motivates people more than celebrating achievements along the way”. I found that on the New Jersey Association of Partners in Education site (NJAPIE for short), so it must be true.

Anyway, I’ve written another of those Gallery2 modules to show some stats on how the 2008 captioning is going. It’s more for my own curiosity and to stop me copying huge reams of SQL into Query Browser. But you never know, you might look at it and say “oh” as well. So, if that sounds like fun you can click Caption Status either here or on the Blakepics left nav.

Your pictures … everywhere

Sunday, January 6th, 2008

Whilst researching Gallery 2 extensions today, I stumbled across the news that PictureSync now supports Gallery2 as an upload medium. I like having all my photos on my own site, so I can do what I like with them without having to pay through the nose to get at the originals, or worrying about migrating them when the next big thing comes along.

That said, I think I often miss out on some of the more social aspects of photography that networks like Flickr, or Facebook provide. So personally, I’m looking forward to the Windows release of this product so I can try it out for myself. Have any of you Mac users out there tried PictureSync? What did you think?

Inline captioning on Gallery2 / Blakepics.com

Sunday, January 6th, 2008

Approximately 20% of the 17,500 photos on Blakepics have captions of any kind. This can be attributed to a whole number of different things.

  1. I’m very lazy.
  2. I have far too many photos.
  3. I put far too many of them on-line.
  4. Captioning photos on Gallery2 is harder than it should be.

Well, one of my new years resolutions last year was “caption more photos”, and without any specific goals - I can say I succeeded tremendously. So this year I thought I’d quantify it so I can feel ever warmer, fuzzier and smug that I fulfilled an ambition for 2008. So I’m aiming to have captions on a massive 35% of them by years end (that’s a minimum of 2,500 more photos), and to help - I’ve armed Blakepics.com with a whole new module. I think I’m finally starting to get to grips with at least some of the Gallery2 API.

So if you have an account on Blakepics.com, you can help out by using this new method of adding captions to your photos. Whenever you’re viewing an album you own or have permissions for (and you’re signed-in of course), you’ll notice a new box called “Change Title” below each thumbnail. Just type your new title into that and click the icon to the right, or just hit enter. The image title will be updated without any reloading the page, or taking you to new forms. Which is especially cool if you’re just browsing the photos and want to quickly update something.

I’ve found it a huge improvement, even over bulk-edit - but please let me know your thoughts. And if you’re interested in this module for your own Gallery, please get in touch. It might not be ready for distribution, but I’m happy to hear from any willing beta testers.

Geonaming your Geotags - Automatic picture captions

Saturday, October 6th, 2007

This time last year, I wrote about how to Geotag your photos using a simple GPS device and oodles of free software. Not much has changed in that process since, except now there’s a lot more software to choose from and the clever folks over at Trackstick.com have made it a lot easier to export your GPX tracks.

The spatially-aware web is producing a lot more services for us to use, and now Geonames.org some excellent reverse geocoding functionality. That’s the process of taking geo-data (such as longitude and latitude) and getting place names back. Which is really cool for tagging, titling or adding descriptions to your geocoded pictures.

They provide an impressive array of web services in both JSON and XML ranging from postal code searches, to reverse geocoding based on the community-based Wikipedia entries. And if that’s not enough for you, you can download a copy of their huge database and manipulate it off-line however you want.

So me, I wrote some JavaScript to take advantage of the reverse geocoding and tied it into the Blakepics Gallery2 Tags module. I’ll take the Wikipedia entries as an example, because that returns the most landmarks for me. The example code at the bottom of the page actually makes use of two more web services in addition.


The URL to call the web service is pretty simple enough:

var url = "http://ws.geonames.org/findNearbyWikipediaJSON?lat=" + lat + "&lng=" + lon + "&radius=10";

I’ve kept everything in JavaScript rather than building any back-end code whatsoever, so you need to make sure to use the JSON web services and take advantage of the script tags to avoid any cross-domain security policies. The JSONScriptRequest library can be a powerful ally here. This leaves my server to do more important things, but it all depends on your needs for the app.

url += "&callback=showWikipediaNames";
bObj3 = new JSONscriptRequest(url);
// Build the dynamic script tag
bObj3.buildScriptTag();
// Add the script tag to the page
bObj3.addScriptTag();

Then on the callback
function showWikipediaNames(wikijsonData) {
var wikiobjects = wikijsonData.geonames;
if (wikijsonData.geonames) {
for (var i=0;i<wikiobjects.length;i++) {
addSuggestion(wikiobjects[i].title)
}
}
bObj3.removeScriptTag();
}

With me so far? The final step in the process is to add the call to the JavaScript into your Gallery2 templates.

<a href="#" onclick="return showGeoNameOptions(this, {$block.gpsinfo.LoadGPSInfo.lat}, {$block.gpsinfo.LoadGPSInfo.lon});">GeoNames</a>

And before you know it, you have suggestions from geonames on how to tag your photos. Now you can go away and make it suggest some titles and descriptions too. If anyone’s interested in packaging this up into a slightly better Gallery module (or any other application), drop me a line. If this is enough for you, download my example and use it as you see fit.

Download

Pre-requisites