Ruben Laguna’s blog

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 .
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


<span class='line'>$cameradate    = mktime(1 , 0, 0, 11, 30, 1999);
</span><span class='line'>$tripstartdate = mktime(10, 0, 0,  3,  2, 2006);</span>

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


Copyright © 2015 - Ruben Laguna - Powered by Octopress