DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Comfortable Exif Writer Using ExifTools

02.02.2007
| 3058 views |
  • submit to reddit
        I felt strange lazy using all that command-line stuff. I wanted to have  kind of a platform-independent command-line front-end for exiftools. Here's what I got:


#!/usr/bin/perl
# 
# writeExif.pl V0.3
# 2007 by S Tayefeh
# http://www.tayefeh.de
#
# This perl-script uses exiftools (http://www.sno.phy.queensu.ca/~phil/exiftool/)
# to write most common tags to a file. usage:
# 
# writeExif.pl [FILENAME]
# 
# (WINDOWS using ActivePerl:
# perl C:/WINNT/writeExif.pl [FILENAME]
# )
#
#
# Just edit the variables here:
#

########## Proceed (=1) or Skip (=0) groups ? #####
$do{"date"}		=1; 	# anything dealing with date/time
$do{"technical"}	=1;	# technical details
$do{"description"}	=1;	# anything dealing with descriptions/keywords/title etc
$do{"place"}		=1;	# City/State/Country
$do{"geo"}		=1;	# GeoTags (Latitude/Longitude/Altitude)
$do{"rights"}		=1;	# Owner/Copyright/Software

########## Place ##########
if($do{'place'})
{
   $para{"City"}		="Heidelberg";
   $para{"State"}		="Baden-Wuertemberg";
   $para{"Country"}		="Germany";
}

########## Get this from e-g. http://www.addressfix.com/ ##########
if($do{'geo'})
{
   $para{"GPSLatitudeRef"}	="N"; 		# N=North S=South
   $para{"GPSLatitude"}		="49.41222269";	# "dd/1,mm/1,ss/1.", or float 49.8724240
   $para{"GPSLongitudeRef"}	="E"; 		# E=East W=West
   $para{"GPSLongitude"}	="8.71022701";
   $para{"GPSAltitude"}		="20"; 		# [meters]
}

########## Technical Details ##########
#
if($do{'technical'})
{
   $para{"Make"}		="MINOLTA";	# Camera Vendor
   $para{"Model"}		="X-300";	# Camera Model
   $para{"ISO"}			="100";
   $para{"Lens"}		="24mm f/2.4";	# Lens Type
   $para{"FocalLength"}		="24";		# Focal Length, e.g: "29.0mm (35mm equivalent: 43.0mm)"
   $para{"FNumber"}		="2";		# Actually used focal tatio, e.g. for f/2.7 Fnumber=2.7 
   $para{"ExposureTime"}	="1/60";	# Exposure time [s]
}

########## Time/Date ##########
$myTime{"Hour"}			='23';
$myTime{"Minute"}		='11';
$myTime{"Second"}		='00';
$myTime{"Day"}			='17';
$myTime{"Month"}		='10';
$myTime{"Year"}			='2005';


########## Description ##########
if($do{'description'})
{
   $para{"Title"}		="Thalia Theater";
   $para{"ImageDescription"}	="Thalia Theater in Hamburg";
   $para{"Keywords"}		="Something, Some, Test, My";
}

########## Rights ##########
if($do{'rights'})
{
   $para{"Owner"}		="Sascha Tayefeh";
   $para{"Software"}		="writeExif.sh by Sascha Tayefeh (http://www.tayefeh.de)";
}


########## Generic Variables ##########
# You do not need to edit these. However, 
# if you want some more specifics, edit these, too:

if($do{'date'})
{
   $para{"DateTimeOriginal"}	="$myTime{'Year'}:$myTime{'Month'}:$myTime{'Day'} $myTime{'Hour'}:$myTime{'Minute'}:$myTime{'Second'}";
   $para{"ModifyDate"}		=$para{'DateTimeOriginal'};
   $para{"CreateDate"}		=$para{'DateTimeOriginal'};
}


if($do{'rights'})
{
   ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday,$isdst)=localtime(time); $year=$year+1900;
   $para{"Copyright"}		=$year." by $para{'Owner'}"; #Copyright
}

if($do{'description'})
{

   $para{"Comment"}		=$para{'ImageDescription'};
   $para{"ObjectName"}		=$para{'Title'};
   $para{"Description"}		=$para{'ImageDescription'};
   $para{"UserComment"}		=$para{'Comment'};
   $para{"Caption-Abstract"}	=$para{'Comment'};
   $para{"Subject"}		=$para{'Tags'};
}

########## -------------- STOP EDITING ---------------  #########


if (!$ARGV[0]) {die "***ERROR: Missing Filename\nUSAGE: writeExif.pl [FILENAME]\n";}

$exifOptions="";
while (($tag, $value) = each(%para))
{
   $exifOptions=sprintf ("%s \"-%s=%s\"",$exifOptions,$tag, $value);
}

#print "$exifOptions\n";

if($exifOptions)
{
$bool=system ("exiftool $exifOptions $ARGV[0]") ;
$bool=system ("exiftool $ARGV[0]") ;
} else
{
   print "All groups switched off... nothing to do\n";
}