GnomePlanet Stock Travel Photography

Register and login to use the Lightboxes and Client Area.

 

There are 0 registered members and 7 guests currently viewing the site.

Member Login

Not a member yet? Sign Up!

 

A password will be e-mailed to you.

Visit the GnomePlanet Stock Travel Photography Gallery for High-Res Stock Travel Photos, Travel Photographer Tutorials, Tips, and Resources  

Batch Geo-Tagging Photos For The Panoramio Uploader

Panoramio External link opens a new Browser window is a community-powered site for exploring places through photography: cities, natural wonders, or anywhere you might go. Panoramio is a showcase for the talents of its contributors, a place to see the world, and a community where members determine the content. Panoramio is different from other photo sharing sites because the photos illustrate places - Panoramio's all about seeing the world. Screenshot of Panoramio Map webpage

I decided to share some of my travel photographs on Panoramio. To do this, the photos need a title and a lattitude/longitude position. When uploading, you can add this information manually, but where a large number of images are needed this would take a huge amount of time, so I looked for ways to automate the process. If the title and position data are saved in the photo's MetaData External link opens a new Browser window, then when I upload the photos to Panoramio, the required information is automatically located and added to their database. That is therefore the obvious approach to take. I normally use the RoboGeo program to geo-tag my photos from a .gpx trackfile, but this time I just wanted to tag some folders of photos from a list of their titles and positions, a task which RoboGeo does not do.

The obvious tool to use when working with anything to do with image MetaData is Phil Harvey's excellent and free program 'ExifTool' External link opens a new Browser window. It is a command-line program, without a GUI wrapper, which some people may find intimidating, but its extreme versatility makes it second to none, so its worth sticking with it and working out how to use it for yourself. It can be used from the Command Line as mentioned, in a simple DOS Batchfile, or run from a Perl program. I chose the latter method.

First of all, I needed to check that the entries in the MetaData that I was writing to were the ones that Panoramio would read. Some early experiments had the position recognised OK, but not the title. After a lot of searching and no information located, I turned for help to the Panoramio Forum External link opens a new Browser window, where one of the moderators, Tomas Kohout External link opens a new Browser window, kindly did some experiments for me to ascertain exactly what the Panoramio Uploader was happy with. You can view the answer in the Questions and Support > Include Metadata in Photo Uploads External link opens a new Browser window thread, but to summarise his information, the following tags need to be written to for the Panoramio Uploader to work correctly:

Tag IDTag GroupTag Name
0x010eEXIF:IFD0ImageDescription
--XMP-dcTitle
5IPTCObjectName
0x0001GPSGPSLatitudeRef
0x0002GPSGPSLatitude
0x0003GPSGPSLongitudeRef
0x0004GPSGPSLongitude

You can read more about MetaTags on Phil Harvey's Guide to Tag Names External link opens a new Browser window page.

I now needed to find some way of getting the ExifTool program to read information from a file and write it to each photo in a directory full of many photos. After more searching, I found this Batch GPS into Exif from text file External link opens a new Browser window thread on the CPAN Image-ExifTool Forum External link opens a new Browser window. The code on that page did a lot of what I wanted, and only required small modifications to adapt for my specific requirements. You can see the full code that I used, after modification, at the bottom of this page.

The program is a Perl program, which means that you need Perl installed on your computer to run it. If you don't have Perl, you can get a free installation at the ActivePerl External link opens a new Browser window website. Next, you need to install the ExifTool perl module. The installation notes External link opens a new Browser window page tell you how to do that - its very easy. Note that it is the 'Full Perl Distribution' section that you want, not the Windows section, as you will be running the batch program from within a Perl environment, not a Windows batch file.

We now need to create an .ini file that contains all of the GPS and Title information for our photos. Here is a sample of my file, with entries for 3 photos.

[C8308.jpg]
{Two yurts with a herd of grazing cattle on the grassy slopes of the mountains.}
geotag=46.9480123749921,102.941160562486
[C8309.jpg]
{Verdant pastureland with distant mountains.}
geotag=46.9530133333333,102.955152666667
[C8322.jpg]
{Dragoman Overland truck crossing a rickety wooden bridge.}
geotag=46.9755376486486,102.967410554054

Note how the filename for the photo is contained between 2 square brackets, and photo title is contained between 2 curly brackets. The lattitude and longitude values are on the 3rd line, separated by a comma. South or West values are negative. North or East are positive, as show here. You don't need a space between each entry. You need one entry for each photo in your directory. You can have more entries than photos, but not more photos than entries in the .ini file. Create the file in a text editor, such as NotePad, NOT a word processor program such as Word. Save the file with a filename of 'geotest.ini'. If you want to use a different name, change the value at line 36 of the 'batch.pl' code.

We are nearly ready to begin! Place the batch program file named 'batch.pl', the photos, and the .ini file named 'geotest.ini' in the same directory i.e. 'C:\geotest'. Click 'Start > Programs > Accessories > Command Prompt' to open a Command Prompt window, and type: 'cd c:\geotest' to change the directory to the one where the batch file program is located. Type: 'batch.pl' and wait a few seconds for the program to work. It will report the names of the files modified, and a total number of the files modified.

Occasionally the program will report '0 files modified' even though you know that there are correct entries for the photos in the .ini file. This could be because the EXIF has been damaged during a TIFF > JPG conversion. If this is the case, the photo metadata can be repaired. To do this, download the Windows Stand-Alone Executable from the ExifTool home page External link opens a new Browser window and follows the notes in the Windows section of the installation notes External link opens a new Browser window. Copy the file 'exiftool.exe' to the directory above the photos, open the Command Prompt, change the directory to the one where exiftool is, and then type:
 
exiftool -all= -tagsfromfile @ -all:all -unsafe DIRECTORY_NAME
 
Re-run 'batch.pl' as above, and all should now be OK.


 
 

CODE FOR THE PROGRAM 'batch.pl' :

#!/usr/bin/perl -w
#
# 'batch.pl' - Original code by Phil Harvey http://www.sno.phy.queensu.ca/~phil/exiftool/
# Description: Adds Title and GPS lat/long information to all images in a directory.
# Sourced from: http://cpanforum.com/threads/4609
# Modified by Tim Makins www.gnomeplanet.com 2012-07-12
#
# General Notes: Panoramio-compatible. Data is specified by the .ini file in line 36.
# It takes a while to run as it checks for every photo listed in the ini positions file.
# I have disabled the error printing on line 103. Remove the '#' to turn it back on.
#
# Ini-File Notes: Each photo needs an entry in the .ini file listing filename, title, lat/lon position.
# Sample 3-line entry from ini file (remove the # characters) :
#  [C0392.jpg]
#  {Interior domes, Islamic caligraphy and artwork in the Sultan Ahmet Camii, or Blue Mosque.}
#  geotag=41.0053589546692,28.9768658158566
#
# To run this batch program:
#  See http://www.sno.phy.queensu.ca/~phil/exiftool/install.html for ExifTool perl module
#  installation notes. Place this batch program, the photos, and the .ini file in the same
#  directory i.e. C:\Programs\ExifTool\geotest
#  Start > Programs > Accessories > Command Prompt
#  From the Command Prompt, type: cd c:\programs\exiftool\geotest
#  From the Command Prompt, type: batch.pl
#  The program will report the names of the files modified, and a total number.
#  Open the directory in RoboGeo to see that the values have been successfully modified.
#
# Error Notes: If some files are not modified, this could be because the EXIF has been
# damaged during the TIFF > JPG conversion. If this is the case, try repairing the directory
# by putting 'exiftool.exe' in the directory above the photos, open the Command
# Prompt, change the directory to the one where exiftool is, and then type:
#    exiftool -all= -tagsfromfile @ -all:all -unsafe DIRECTORY_NAME
# Re-run batch.pl as above, and all should now be OK.
#
use strict;

# name of .ini file
my $file = "geotest.ini";

# include the location of exiftool
BEGIN { push @INC, "c:/windows/lib" };

 use Image::ExifTool;

 my $exifTool = new Image::ExifTool;
 
 # reset the file counter
 my $count = 0;
 
 open FILE, $file or warn("Error opening $file\n"), next;
 my ($dir,$name,$title);

 # get the directory of the .ini and image files
 if ($file =~ /(.*\/)/) {
 $dir = $1;
 } else {
 $dir = './';
 }

 # process the .ini file
 while () {
 # look for image file name
 /^\[(.*?)\]/ and $name = $1, next;
  # look for image title
 /^\{(.*?)\}/ and $title = $1, next;
 # look for GPS position
 /^geotag=([-+]?[.\d]+),([-+]?[.\d]+)/ or next;
  unless ($name) {
  warn "No file for position $1, $2\n";
 next;
 }

 # set necessary GPS tags
 my ($lat, $long) = ($1, $2);
 my ($latref, $longref) = ('N','E');
 $lat < 0 and $lat *= -1, $latref = 'S';
 $long < 0 and $long *= -1, $longref = 'W';
 $exifTool->SetNewValue(GPSLatitude => $lat);
 $exifTool->SetNewValue(GPSLatitudeRef => $latref);
 $exifTool->SetNewValue(GPSLongitude => $long);
 $exifTool->SetNewValue(GPSLongitudeRef => $longref);
 $exifTool->SetNewValue(ImageDescription => $title);
 $exifTool->SetNewValue(Title => $title); 
 $exifTool->SetNewValue(ObjectName => $title);  

 # rewrite file to temporary file
 my $img = "$name";
 my $tmp = $img . '_tmp';
 -e $tmp and warn("Temp file $tmp exists!\n"), next;
 my $result = $exifTool->WriteInfo($img, $tmp);
 if ($result == 1) {
  if (rename $tmp, $img) {
  # overwrite original file with updated file
  print "$img updated\n";
  ++$count;
  next;
 } else {
  print "Error renaming $tmp\n";
 }
 } elsif ($result == 2) {
 print "$img unchanged\n";
 } else {
# print "Error updating $img\n";
 }
 unlink $tmp;
 }

 print "$count files updated\n";
 # end

Stock Photograph Search

Advanced Search Page

Latest Photos

Bathers at Ganges Sangam watch pilgrims cross Ganges river on pontoon bridge.visitors on the Isla Pescado view the Uyuni Salt Flats.
Great Southern Rail carriage attendants on the Indian Pacific long distance train.Mass crowds of Indian Hindu pilgrims cross pontoon bridge over Ganges river.
Woman in sari walks through Ganges River shallows at dawn for a ritual bath.Wine tasting at the Bodega El Transito winery.
View some of the latest images posted to GnomePlanet Travel Photography

Random Photo

Forest of Monkey-puzzle Trees (Araucaria araucana) in front of the Lanin Volcano.

Forest of Monkey-puzzle Trees (Araucaria araucana) in front of the Lanin Volcano..

free counters

Web design by gnomeplanet.com   ::   All images and pages on this site are © 2008 - 2024 and remain the property of gnomeplanet.com   ::   All rights reserved