Header Image

Geo-tagging Photographs

June 25th, 2015

Recently I have been trying to get all the photographs I have taken over the last few years organised and shared on the web. The need to easily share the photographs led me to develop a simple PHP web based photo gallery browser which you can find here.

As part of the organisation process, the subject of another blog post in the near future, I really wanted to add GPS data to the photographs. After countless hours messing about with a number of command line tools including ImageMagick., I found that the ExifTool application offered the easiest way to manipulate the GPS data in the EXIF metadata. ExifTool is a platform-independent Perl library plus a command-line application for reading, writing and editing meta information in a wide variety of files and it accepts a wide range of GPS data and automatically formats it in the correct format, for more information view the documentation. That means I did not need to use other Perl library tools such as Image::ExifTool::Location which only accepts decimal coordinates and Geo::Coordinates::DecimalDegrees to convert from non-decimal (degree, minutes, seconds) coordinates.

screenshot google maps geo coordinatesObtaining the GPS data is not very tricky and I find using Google maps the better option. You could use the process described here but I find that simply searching and pin pointing the photos' location on Google maps and then extracting the coordinates from the URL in the address bar (see image). You could also use Bing Maps as explained here.

The issue with the ExifTool both as a Perl library and on the command line is that to input the fields separately. To enter valid GPS data you need to set not only GPSLatitude and GPSLongitude but also GPSLatitudeRef and GPSLongitudeRef which the tool does not do automatically as you would expect. In reality you should also be setting the the GPSAltitude and GPSAltitudeRef as well.

The result was a small Perl script that accepts both decimal and non decimal coordinates and applies them to the selected file or files. A copy of the script can be obtained from my github repository.