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.

Auto-captioning photos with CAPTCHAner

Sunday, January 13th, 2008

I quite often have completley unachievable ideas, that have no basis whatsoever in fact or reality. So, it’s no surprise that a conversation with Craig, down the pub on Friday has sparked another of them.

It’s become a bit of a theme this year, and after my last posts on the subject - we got to talking about captioning photos. Many of my photos exist on the basis of seeing something shiny, and then taking a picture. I often have no idea what said shiny thing was - but quite often make the effort usually on Google, or Rough Guides to discover its secrets afterwards.

I encourage any account holders to tag as many photos as they want on Blakepics. But mine is a very small community, and Flickr shadows it with even its tiniest fingernail. So, why should you have to tag your own photos? Aren’t there plenty of other people out there that would do that for you?

And I got thinking about the recaptcha project. They use scans of words to present the user with captchas that will help their digitization of old texts. These “unknowns” are combined with”known” text, and the answers compared against previous users results.

So, why not the same for photos? A known photo could be presented to the user “Dog”, “Cat”, “Llama”, or even a traditional captcha. Combine that with an unknown photo, and invite users to give it a caption. According to recaptcha, there are 60 million captchas being solved every day - it’s about time we put all that to good use.

Or perhaps CAPTCHA might just become another word for blackmail. Sure, you can login to your account - but you have to do something for me first. I just like the way Captchaner, sounds (Captcha, Captioner - see what I did there?). Maybe one day we’ll see this on all of our logins.

Mobile Blakepics with Gallery2, AddViaEmail, Gmail, Symbian and Shozu

Wednesday, September 12th, 2007

12092007013.jpg
The plan was to get photos on Blakepics without the hassle of using computers, web browsers, memory card readers, cables, wires or Royal Mail. The secondary goal of the whole thing is to be a bit cool - so naturally it’s a mash-up of a number of different partially connected services, and I’ll briefly mention Facebook just so that we can check that one off and call it Web 2.0.

So, first step - Gallery2 has an AddViaEmail module. Install that, signup for a Google Mail account and get yourself a really obscure email address. Once you’ve got the AddViaEmail installed and configured (yep, it supports Google’s SSL pop3 servers), you can send emails to that address and have them automagically added to a specific album on your Gallery2 server.

You could stop here if you like - most mobile phones come with email software nowadays. So you can write an email, attach your images, and off they go. But I find email on the little keypads really annoying. And there’s all that typing, clicking, and making sure you get things right to worry about. You’re not exactly cutting edge, with email … are you? Besides, we’ve only made use of three different vaguely related services. That’s not what the web of the future is all about. I’ve heard about it in fairy tales.

So, get yourself a Shozu account. They provide a really cool backup / Share-It service and comes complete with a Symbian application which you can install on your brand new ultra-shiny Nokia N95. For example. If you use this, you can get yourself some single-click access to uploading your photos. Actually, it’s a 3-click minimum. But it’s better than typing email addresses or searching for contacts. They provide a bunch of other ways of sharing your photos, such as uploading to the BBC for consideration as part of their stories. Or more usefully to a Wordpress blog or Facebook to humiliate your mates before they’ve got home from the pub and had a chance to de-tag all your new compromising photos.

But alas, AddViaEmail and Shozu don’t play very nicely. So, here are some changes to make to your php script (don’t be scared, it won’t bite).

/modules/addviaemail/classes/AddViaEmailHelper.class - Fix problems with the mime type…
list ($ret, $item) = GalleryCoreApi::addItemToAlbum($pathToSaveFile . $filename,$filename, $filename, $summary, '', $mimeType, $targetDestination);
->
list ($ret, $item) = GalleryCoreApi::addItemToAlbum($pathToSaveFile . $filename,$filename, $filename, $summary, '', ‘image/jpeg’, $targetDestination);
You’ll also need to disable the subject line spam checker as Shozu will send your email with the subject line as the name of the image.

So just remove this:

$header_info->subject == $subjectToMatch &&

The spam checker is actually quite a cool function, so one of these days I’ll come back an regular expression that. But quite likely, I probably won’t post it here. So work it out for yourself :)

See, and that’s all there is to it. I can now upload loads of photos direct through my phone (as I did with the image at the top of the page), and you could too.

Hacking the Facebook Developer API

Sunday, June 3rd, 2007

It’s been a while since I’ve written very much code just for myself, rather than everyone else. So this weekend I’ve decided to jump onto the Facebook API and learn a little bit more about the Gallery2 API in the process.

Why?

I have thousands of photos on Blakepics, and Facebook comes along and wants me to upload them all over again. Well, sure, I can do that - or, it makes a lot more sense to combine the power of the two systems.

What?

Wanting to keep this initial trial run extremely simple - I’ve gone for just adding a link below my profile picture. That way I can keep very clear of the Gallery API for the time being effectively reducing my problems by half :)

How?

  1. User adds the Blakepics application on Facebook
  2. Setting the Callback URL on Facebook, a request is made to Blakepics.com
  3. Blakepics.com makes use of the Facebook API to check the currently logged in user
    // the facebook client library
    include_once(’../modules/facebooktaggedalbums/api/client/facebook.php’);
    include_once(’../modules/facebooktaggedalbums/api/client/facebookapi_php5_restlib.php’);
    // some basic library functions
    include_once(’../modules/facebooktaggedalbums/api/lib.php’);
    // this defines some of your basic setup
    include_once(’../modules/facebooktaggedalbums/api/config.php’);
    $facebook = new Facebook($api_key, $secret);
    $facebook->require_frame();
    $user = $facebook->require_login();
  4. Using this user ID, Blakepics requests the first and last name of that user from Facebook
    $user_info = $facebook->api_client->users_getInfo ($user, 'first_name,last_name');
  5. Generate a URL that links to the tagged album, e.g. http://www.blakepics.com/key/kevin+blake. Using the rather cool FBML (FaceBook Markup Language), the link can be sent to Facebook with the instruction that this should be applied as a profile action (fb:profile-action).
    $fbml="<fb:profile-action url=\"http://www.blakepics.com/key/" . $user_info[0]['first_name'] . “+”.$user_info[0]['last_name'].”\”>View more Photos of me at Blakepics</fb:profile-action>”;
    $facebook->api_client->profile_setFBML($fbml, $user);
  6. And display a message back to the user, to let them know what’s happened
    print "Blakepics profile link has been added";

And that’s it really. Obviously there’s a lot more that can be done, but the simple application works and is on its way to approval from the Facebook team. All being well, you should be able to add your own links to tagged albums very shortly.