EXIF: Rename JPG by Timestamp and Add Copyright
Update 2016. I still use these scripts to process photos.
Summary
Below are three small perl scripts that makes use of the exiv2 application to manipulate EXIF data in a JPG file. They are single loops that can change the value of the meta data associated with a JPG file (the data about camera, shutter speed, copyright, etc.), or a whole directory of JPG files. One script simply renames photos to their timestamp.
Note: I have a different Perl rename files script if you want to rename using text instead of a timestamp. There is also a perl script to add EXIF dates to photos, if have a scanned photos or negatives with the incorrect timestamps.
Files
Below is the content of the perl script that renames a file by timestamp and edits EXIF data. You can comment out the EXIF part to only rename file.
#!/usr/bin/perl -w
#
# 2007-07 http://kimbriggs.com/
# Script uses the exiv2 program http://www.exiv2.org/
# to add EXIF metadata to JPGS and rename with timestamp.
#
#Get the year of copyright
print "Enter the Year: ";
chomp($year = <>);
#Load all jpgs into an array.
@pix = `ls *.JPG`;
foreach $pix (@pix) {
#Let you know it's working
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 YOUR_NAME_HERE' $pix");
system("exiv2 -M'set Exif.Image.Copyright Copyright $year YOUR_NAME_HERE.' $pix");
system("exiv2 -r %Y_%m%d_%H%M%S $pix");
}
- Rename the file to “rename-timestamp.pl” (or something that ends in “.pl”)
- Edit it with a text editor to make sure you are adding your own information if you are editing the EXIF data. I like geany.
- Put the file in a directory with the JPGs you want to modify (note that the script currently is set for my camera, which names files with capitals). Type
perl rename-timestamp.pl
and press Enter/Return. That’s it.
Remarks
What a great find this was. There are a bunch of programs in the Ubuntu Linux software listings for programs that print out the EXIF, or metadata, about JPG files. A couple of the applications can rename the file, but the Exif and IPTC metadata tool exiv2 was the only one I found that really makes it easy to manipulate all of the EXIF data. There are some advanced tutorials on the website if this script is too basic for you. To install the exiv2 program, you can either type sudo apt-get install exiv2
in a terminal window or use System -> Administration -> Synaptic Package Manager and search for exiv2. Perl should be available to you already.
To find out all of the possible information you can edit for a file named “file_name.JPG”, type the following in a terminal once you are in the same directory as the file: exiv2 -pv file_name.JPG
. Just compare the data you see with the script to decide whether you need to type “Exif.Image.value” or “Exif.Photo.value“.