Ruben Laguna's blog

Sep 13, 2006 - 2 minute read - camera date exif headers pel photo photos php script Uncategorized

PHP script to update the date in the exif photo headers

When I returned from my trip to NYC I realized that the camera was set to the wrong date!. I left the camera without batteries a long time and the camera reset to year 1900. So all photos had the wrong date in the EXIF headers, with 295 photos manually correct each one was not an option. Well. I realized that all I have to do to correct the photos is take one phote see the date in that photo and substract that date from the actual date of the photo to obtain the time difference between the photos. Then I wrote a php shell script to walk over all photos and add that time difference to each photo. The script is here updatedate.zip .
Before you try to execute it you need php 5 and pel (php exif library).
But beware pel-0.9 has a bug in the PelTag.php file, so you will have to download the latest peltag.php from cvs. If you see the following error that means that you have the old PelTag.php
`Fatal error: Cannot redefine class constant PelTag::XP_COMMENT in pel\PelTag.php on line 1086`

And then all you have to do is to edit the update.php file and put the dates there

$cameradate = mktime(1 , 0, 0, 11, 30, 1999);
$tripstartdate = mktime(10, 0, 0, 3, 2, 2006);

the mktime format is documented here.

mktime* (hour,minute,second, month,day,year)

The command line format is

php updatedate.php xxx.jpg

and it will output to filename with the prefix “new-”. If you want to apply it to a several files then you can do

ls *.jpg|xargs php updatedate.php