Update 2016:  I still use this script to process scanned photos and negatives.

Summary

This page describes a perl script that can be used to add EXIF date and copyright values to a series of JPG files. This may be useful to give missing EXIF tags to JPGs created by scanning a photo or a negative. The JPGs will then sort properly by date in most modern graphics programs.

Note: If you already have an original digital photo, I have a simpler script to add copyright information and rename JPGs by timestamp.

Background

The Exif and IPTC metadata tool exiv2 is used to change the internal "date created" and "date digitized" values that modern graphics programs use to order your files by date. Exiv2 is a free software program that is available in many linux distributions including Ubuntu. There is a Windows version of exiv2, but the directory listing part of this script would need to be re-written to work under Windows. (If you get it to work under Windows, please email me a link to post here). I noticed that the Windows file browser under Windows XP uses a different date for the photo timestamp than the linux file browser. That is why there are multiple instances of the date inserted.

Procedure

IMPORTANT! You NEED to work on COPIES of your original photos until you are completely satisfied with the final result of all the images. You can permanently mess up the internal metadata of the files if it is manipulated incorrectly. EVERY TIME, really. You have been warned.

The main application I can think of for this script is to catalog your old rolls of film along side your digital photos. The script will handle batches of photos up to 59 at a time. You will be prompted for a year, month, and day. The script then gives the photos a timestamp in increments of 1 minute, starting at noon. So, for example, if you entered 1995, 06, and 15. The photos will have NEW NAMES equal to the time stamps, which are incremented by 1 minute each iteration of the loop. For a 24 exposure roll, you would get filenames like this:

1995_0615_120100.JPG
1995_0615_120200.JPG
1995_0615_120300.JPG
...
1995_0615_122400.JPG

If you do NOT want to rename the files, and only want to change the internal EXIF data, follow the instructions in the script to comment out the line near the end.

  1. Copy the contents of the script below or get it directly as a text file. Paste it into a text editor (on a Linux Gnome desktop, Applications... Accessories... Text Editor) and save the file with a ".pl" extension, so you and your shell know it's a perl script.
  2. Make sure that your copy of this script is executable. Right-click on the file and click on the "Permissions" tab. Click in the box shown below to make executable.

  3. Separate the JPGs you want to process into folders according to the date you want them all to share. I suggest that if you have a roll spanning multiple months, pick an average for simplicity. At least they will be in a relative order and work with most graphics programs.
  4. Paste a copy of the executable script file in each folder of JPGs you want to process.
  5. Use your file browser to get to each folder and double-click the script and choose "Run In Terminal" from the dialog box that pops up.

  6. Enter data as you are prompted and press the Enter/Return key. The value for "Your Name" will be put in the Copyright and Artist fields. The year, month, and day are required as *numbers*, not text, and the script will fail without them.
  7. Check the data for some random files. At least one per folder. Right-click on a file and choose "Properties" and then click on the "Image" tab. Below is an example of what you would see if your name was "Kim Briggs" and the file was the 31st image processed for April 1st, 1980, i.e., the values entered in the terminal prompts were "Kim Briggs", "1980", "04", and "01" (without the quotes).

Note: If you make a mistake when entering the data, you can use the Ctrl+C key combination to cancel the script.

Contents of the Perl Script

#!/usr/bin/perl -w
#
# ADDING DATES TO SCANNED PHOTOS OR NEGATIVES
#
# Kim Briggs 2009-12 http://kimbriggs.com
#
# Script uses the exiv2 program http://www.exiv2.org/
# to add EXIF date and metadata to JPGS (and rename with new timestamp).
#
# Process ONE ROLL of film at a time (59 pics max).
# Numbering sequence is from NOON, i.e., 120100 to 125900.
#
# Reference of EXIF format: Date Taken: 2009:10:07 15:24:02
# ModifyDate=DateTime(EXIFspec)
# CreateDate=DateTimeDigitized(EXIFspec)
# DateTimeOriginal(ExifIFD)
# exiv2 -pt = print all the exif tags to screen
#

print "Enter Your Name: ";
chomp($my_name = <>);

print "Enter the Year(YYYY): ";
chomp($my_year = <>);

print "Enter the Month(MM): ";
chomp($my_month = <>);

print "Enter the Day(DD): ";
chomp($my_day = <>);

# Load all jpgs into an array. Use the same suffix for all files to preserve your order.
# There will be an error message about the suffix you didn't use. Ignore it.
@pix = `ls *.JPG *.jpg`;

$my_count = 0;

foreach $pix (@pix) {

if ($my_count < 10) {$my_count="0$my_count";}

print "Processing photo: ".$pix;
# Use the program exiv2 to process EXIF metadata and rename the file with timestamp

system("exiv2 -M'set Exif.Image.Artist $my_name $my_website' $pix");

system("exiv2 -M'set Exif.Image.Copyright Copyright $my_year $my_name. All Rights Reserved.' $pix");

system("exiv2 -M'set Exif.Image.DateTime $my_year:$my_month:$my_day 12:$my_count:00' $pix");

system("exiv2 -M'set Exif.Photo.DateTimeOriginal $my_year:$my_month:$my_day 12:$my_count:00' $pix");

system("exiv2 -M'set Exif.Photo.DateTimeDigitized $my_year:$my_month:$my_day 12:$my_count:00' $pix");

# Comment out the line below with a "#" symbol to AVOID RENAMING the file.

system("exiv2 -r %Y_%m%d_%H%M%S $pix");

$my_count = int($my_count) + 1;
}

NOTE: There is no error checking. You could potentially enter illegal dates in the date fields, so check them when you are done. Delete the bad files and make NEW COPIES to work from if you make a mistake.