1169 words
Yikes! Geotagging probably is a mindless hype word, but it’s the kind of thing that I find interesting – particularly for image files. With geographical information at your fingertips you can’t only find your photos by folders, names or dates. But you’ll also be able to find them based on their location in the world. That’s particularly interesting as many photos – many of my photos at least – are taken when traveling, so it might enable us to keep photos from different trips to the same location together. Or, using sites like Flickr and Geobloggers, it may even enable you to see other people’s photos from the same places you’ve visited without significant effort.
Having been through the metadata war for addresses and music – i.e. those countless moments of time you spent on correcting typos, adding cover art or graphics, adding tags and so on – we know that creating metadata that are correct, uniform and precise enough can be a pain. And if it is to be done, it better require not a lot of effort. I am tempted to say that easy metadata editing and most significantly batch metadata editing is one of the big strengths of iTunes and the main reason why iTunes libraries tend to be slightly less chaotic than other digital music collections.
So I ended up thinking about making a tool that uses Google Maps to let me easily specify a location on earth and then adding that information to image files. The geographic information is stored in GPS EXIF tags and will be displayed by recent versions of iPhoto or GraphicConverter. Those applications don’t seem to offer editing of those tags, though, so my little project stalled for a while until I recently read Martin Pittenauer’s post on using PithHelmet to integrate Google Maps with geocoded images in Flickr and received a hint there pointing to ExifTool which reads and writes many metadata of image files.
It’s a Perl and command line thing. But it’s not too hard to use. So all I had to do was wrap it in an AppleScript that gets a location from a Google Map and inserts it into image files. Those Google Maps turned out to be quite messy in the way their scripts look. And I’m neither a big fan nor a big connoisseur of JavaScript, but with a bit of playing around and some helpful words from Alf it ended up being quite easy to extract the current coordinates from a Google Maps page.
After a few of the usual fights with AppleScript (which doesn’t seem to have an abs()
function), I could piece all these things together to get a script that does exactly what I want. In case you’re interested in this as well, I’ll give a short rundown of what you need to do to get this on your computer. It’s not quite comfortable right now, unfortunately. So here we go:
Get a copy of ExifTool and put it on your computer. If you rename the folder from that download to ‘ExifTool’ and put it in a folder named ‘bin’ in your home folder as shown in the screenshot below, the script you can download with will work right out of the box.
If you put ExifTool in the location mentioned in the first step, you can skip this step.
In you put ExifTool in a different location, you need to adapt the script so it knows where ExifTool is. Open the script in Script Editor, read the notes and change the property at the very top of the script to give the proper path to your copy of ExifTool.
Once the setup is done, you’re ready to use the script.
Not that I’ve seen it happen, but there seems to be a slight possibility of ExifTool trashing your photos while manipulating the tags. ExifTool usually makes the tag changes in a copy of the original image. As that wouldn’t be convenient when you’re manipulating the metadata of files you have ordered before – or that you are using in iPhoto – I have set up the script to edit the files themselves. Thus be sure to have backups of the files around in case something goes wrong.
Yup, the setup process is a bit annoying right now. It should be easy to support other image manipulation applications in case they have AppleScript support. I am not too optimistic about getting it to work with Mozilla based browsers as their AppleScript support seems to be even worse than Safari’s.
There are many other little annoyances as well. Like the script itself not being user friendly and not doing error handling. Such as iPhoto apparently caching the GPS data when importing a photo and thus claiming non-existant GPS information even after you’ve added it. GraphicConverter and Preview are more mild on this. While they won’t update the EXIF information they display immediately, re-loading the file will give the expected results. (It’s a shame that Preview doesn’t do this automagically – after all Cocoa applications tend to have a certain awareness of changes to open files.)
In addition, it seems that Spotlight doesn’t index the GPS information. Which is a shame. Smart folders of photos I took in Göttingen, around Cape Town, in Las Vegas… would’ve been nice.
The final disappointment was Flickr. While there seems to be geotagging going on there and while Flickr can read the GPS data within the EXIF data, those two things seem to be unrelated and all the useful things Flickr should be doing automatically have to be done by the user or even more tools.
To sum up: What I had in mind can be done. But the way to get there isn’t as smooth as I’d like it to be. In addition, right now, the direct uses I had in mind for geographical metadata in photos – for Flickr and for Spotlight – don’t work.
Hi, thanks for the Applescript…pulled together several things I’ve been working with. ` I had to make one change for it to work with (I guess it has to do with US number seperators.)
on decimalToTraditionalDegrees(input) set input to my abs(input) set myDegrees to (input div 1) set a to 60 * (input - myDegrees) set myMinutes to (a div 1) set b to 60 * (a - myMinutes) set mySeconds to (b div 1)
--jcb changes below set olddelims to AppleScript's text item delimiters set AppleScript's text item delimiters to "." set c to text item 2 of (b as string) -- set c to 100 * (b - mySeconds) set theSeconds to (mySeconds as string) & "." & c as string set AppleScript's text item delimiters to olddelims --end of changes return {myDegrees as string, myMinutes as string, theSeconds}
end decimalToTraditionalDegrees
` ..so does the EXIF spec REQUIRE traditional degrees (I guess I can look up the answer to that myself.)
Thanks again!
jcb, thanks for that.
Indeed, I only needed to insert those lines of code because of the different localisations of MacOS. AppleScript’s number to string conversion seems to always use the decimal separator as set in the system preferences. And for German systems that’s a comma by default. Unfortunately, you can’t pass the number to exiftool as it requires you to use . as a decimal separator.
I have included your improvement into the script now, so it should run properly on systems using a . as a decimal separator as well.
does the EXIF spec REQUIRE traditional degrees (I guess I can look up the answer to that myself.)
I think so. At least all EXIF reading applications I’ve seen, display the location that way. More importantly for this case, exiftool requires this kind of input, so there’s no way around it.
Very interesting, check out my blog for more information about georefrencing. the adress is http://geo.novelviews.com
I’ve been trying unsuccessfully to update this to support the current version of Google Maps. On the surface, it appears modifying the Javascript to “document.title = gApplication.getMap().getCenter().toUrlValue();document.title;” would be sufficient, but I’m missing a reference somewhere.
Any chance you’ve been through this already?
Sorry, haven’t looked at it for a while.
Google Earth supports AppleScript! I updated the script by replacing the getGoogleMapsCoordinates() function with:
on getGoogleEarthCoordinates() tell application "Google Earth" set coords to GetViewInfo set long to longitude of coords set lat to latitude of coords end tell set newLong to decimalToTraditionalDegrees(long) if long > 0 then set eastWest to "E" else set eastWest to "W" end if set newLat to decimalToTraditionalDegrees(lat) if lat > 0 then set northSouth to "N" else set northSouth to "S" end if return {newLat, northSouth, newLong, eastWest} end getGoogleEarthCoordinates
That’s excellent Nate!
I took the liberty to integrate your improvement into my script (and also add support for the nice wikimapia site as well).
How cai I reload an image in iPhoto?
Hi!
I can’t edit the script. Script Editor runs it rather than displaying it.
Is it compiled?
Pierre
Odd, I just double checked and things work fine over here. I put the file into a zip archive now. Try to re-download that. Perhaps it fixes your problem (although I wouldn’t know why…).
This really sounded good until I read the part about putting the EXIF Tool in my Path. That went way over my head. I use a G5 for most of my work but beyond the desktop, even a MAC is a jungle to me.
Is there some more complete “cookbook” instruction on installing these apps? I need a “little” more detail.
Thanks,
Don
Don, I tried clarifying the steps you need to follow above. HTH.
As most of you I’ve been trying out solutions like this as well. Scripts like this and others which integrate GPX files and photos are great but iPhoto is the roadblock here. If you modify a photo (rotating the picture would be enough) all GPS metadata is gone. Seems that iPhoto removes this and I hate it. How can I trust the program when some of my work is lost the next time I tweak my photo?! Anyone with a solution for this?
Yeah, iPhoto definitely isn’t good at these things :( All we can do is hope for the next version, I guess.
Has anyone already set this up to work with Aperture? Using Google Earth to tag the currently selected images in Aperture would be the bee’s knees.
Certainly not me as I don’t have a copy of Aperture.
I’m also wondering whether Aperture is better than iPhoto in recognising and preserving these metadata in your files.
The latest version of iPhoto, I downloaded the update a few minutes ago, seems to keep the GPS tagged photos when I rotate or duplicate my photo’s which is great news. A little closer to the full GPS solution.
I’m using GPS Photo Linker to tag my photo’s (a little easier than a command line program) but I misses the iPhoto integration. I would love to see this program as an iPhoto plug-in or at least with the iPhoto selection screen instead of the finder view.
Maybe one day it would be easy to geotag your photo’s…
I just tried to use this script on the latest version of OS X with the latest version of iPhoto and I’m sorry to say it doesn’t work :(
The script runs without obvious errors and says it has edited one photo (I only selected one) but when I look at the properties of the image the geo data is not there. I tried exiting iPhoto and starting it again to make sure the old exif data wasn’t being cached but to no effect.
I’d be REALLY interested in getting something like this working so if you could release a tweaked version for iLife ‘08 I for one would be very grateful.
Thanks for your work on this worthy project to date.
Bart.
Bart, I do not have iPhoto ’08, so I can’t really try things out at this stage. However, if iPhoto ’08 is like iPhoto 6 and the ‘looking at the properties’ you mention refers to the information window for a photo in iPhoto itself, then I wouldn’t expect the updated GPS information to show up there even if writing it had worked. iPhoto 6 seems to read that information once when it imports the photo and then just keeps displaying the values (or the lack of values) it found at that time even if things have been updated.
The first thing you should try is dragging a photo you ran the script on to the Preview application and checking whether the GPS information is displayed there in the Details tab of the information panel. In iPhoto 6 at least, it will be. So with a bit of luck this is also the case for iPhoto ’08.