Change EXIF date to file name

Started by captainbogart, February 26, 2013, 06:21:12 PM

Previous topic - Next topic

captainbogart

Unusual?  A few weeks ago I changed the file names of about 400 jpgs to the EXIF date.  But I guess I wiped the EXIF date!??!  Ooops!  I at least have the date and time... it's the filename!  YAY!  I have no idea how to put it back though (and keep the filename... crazy Olympus with it's wacky file naming scheme).

Help!  Thanks.  Help!
-Chris

Phil Harvey

Hi Chris,

With some luck, reading this thread may answer your questions.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

captainbogart

Thanks Phil.  I tried.

I have 370 images.  I did what you said on the whole folder and got this....

Last login: Tue Feb 26 20:50:54 on ttyp2
Welcome to Darwin!
unknown000393d892cc:~ captainbogart$ exiftool "-datetimeoriginal<filename" /Users/captainbogart/Desktop/images
Warning: Suspicious IFD0 offset for ImageDescription - /Users/captainbogart/Desktop/images/20120106224215.jpg
Error: [minor] Suspicious IFD0 offset for ImageDescription - /Users/captainbogart/Desktop/images/20120106224215.jpg
....
<SNIP.SNIP.SNIP--whole lotta filename snipped>
....
Warning: Suspicious IFD0 offset for ImageDescription - /Users/captainbogart/Desktop/images/20130203053449.jpg
Error: [minor] Suspicious IFD0 offset for ImageDescription - /Users/captainbogart/Desktop/images/20130203053449.jpg
Warning: Suspicious IFD0 offset for ImageDescription - /Users/captainbogart/Desktop/images/20130203053503.jpg
Error: [minor] Suspicious IFD0 offset for ImageDescription - /Users/captainbogart/Desktop/images/20130203053503.jpg
    1 directories scanned
   40 image files updated
  330 files weren't updated due to errors
unknown000393d892cc:~ captainbogart$ 

It looks like it actually worked on the first 40 in "alphabetical" order and then gave up.
Huh?  All in all I think I did pretty good for my first ever excursion into the Terminal application.

captainbogart

OK.  I read a little further and fixed the errors but NOW (heh heh)... the new problem is I'm not getting
a time and date when I read the files with PHP like so...

$exif = exif_read_data($SSImg.$a_img[$x], 0, true);
$titleTime = convertExifToTimestamp($exif['IFD0']['DateTime'], "F j, Y - g:ia");

where function convertExifToTimestamp is...

function convertExifToTimestamp($exifString, $dateFormat)
{
  $exifPieces = explode(" ", $exifString);
  return date($dateFormat,strtotime(str_replace(":","-",$exifPieces[0])." ".$exifPieces[1]));
}

I looked at the files before uploading them to my server and the dates and times HAVE been corrected to match the filenames (thank you, Phil!) but it's not returning the correct times and date to my PHP function.
Go figure.  I'm pretty new to PHP also.

captainbogart

Got it all figured out.  ["EXIF"]["DateTimeOriginal"] was what I needed.  NOT ['IFD0']['DateTime'].  Sorry to be a pain in the ***!  Thanks again Phil.  I WILL be back with more boring, bothersome questions eventually.  Love your work.

Phil Harvey

Great, glad you got things working!

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).