Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "Taken Date" of a photo instead of "Modified Date" with PHP exif_read_data

Tags:

php

image

exif

I'm retrieving the creation date from a photo with exif_read_data PHP function (see the code below.) The dates retrieved from photos that haven't been modified return "Date Taken". Those that have been modified - "Date Modified". Is there a way to get the date a photo was taken, ignoring the "Date Modified" field?

$exif_data = exif_read_data ($filename);
if (!empty($exif_data['DateTime'])) {
    $exif_date = $exif_data['DateTime'];
}

Thank you.

Edit: I think $exif_data['DateTime'] uses the first available date field. Since unmodified images had the same value for "Date Modified" and "Date Taken" it was always retrieving "Date Modified" in my case.

like image 566
Dima Avatar asked Dec 02 '12 21:12

Dima


2 Answers

Okay, I know this is a bit late as this question was posted a year ago, but I am posting this answer because I had the same question and my husband showed me a trick or two about how to get the answer, so I am sharing it. Write a php script to print out the exif_read_data array and you will find all sorts of interesting information. This (below) was printed on command line to stdout using print_r(). If you scroll down you will see two very interesting keys: [DateTime] => 2011:06:21 17:50:57 and [DateTimeOriginal] => 2011:06:04 08:56:22

I hope these will help you get what you need.

Array
(
    [FileName] => Pirate(F).JPG
    [FileDateTime] => 1405733742
    [FileSize] => 4017033
    [FileType] => 2
    [MimeType] => image/jpeg
    [SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, COMMENT, EXIF
    [COMPUTED] => Array
        (
            [html] => width="2592" height="3888"
            [Height] => 3888
            [Width] => 2592
            [IsColor] => 1
            [ByteOrderMotorola] => 1
            [ApertureFNumber] => f/16.0
            [Thumbnail.FileType] => 2
            [Thumbnail.MimeType] => image/jpeg
        )

    [Make] => Canon
    [Model] => Canon EOS DIGITAL REBEL XS
    [Orientation] => 1
    [XResolution] => 4718592/65536
    [YResolution] => 4718592/65536
    [ResolutionUnit] => 2
    [Software] => QuickTime 7.6.9
    [DateTime] => 2011:06:21 17:50:57
    [HostComputer] => Mac OS X 10.5.8
    [YCbCrPositioning] => 1
    [Exif_IFD_Pointer] => 260
    [THUMBNAIL] => Array
        (
            [Compression] => 6
            [XResolution] => 4718592/65536
            [YResolution] => 4718592/65536
            [ResolutionUnit] => 2
            [JPEGInterchangeFormat] => 628
            [JPEGInterchangeFormatLength] => 4867
            [YCbCrPositioning] => 1
        )

    [COMMENT] => Array
        (
            [0] => AppleMark

        )

    [ExposureTime] => 1/200
    [FNumber] => 16/1
    [ExposureProgram] => 2
    [ISOSpeedRatings] => 400
    [ExifVersion] => 0220
    [DateTimeOriginal] => 2011:06:04 08:56:22
    [DateTimeDigitized] => 2011:06:04 08:56:22
    [ShutterSpeedValue] => 499712/65536
    [ApertureValue] => 524288/65536
    [ExposureBiasValue] => 0/1
    [MeteringMode] => 5
    [Flash] => 9
    [FocalLength] => 18/1
    [ColorSpace] => 1
)
like image 54
paidforbychrist Avatar answered Sep 16 '22 13:09

paidforbychrist


The solution is easier then I thought. I was referring to a wrong tag. To get date taken use:

$exif_data['DateTimeOriginal'];

like image 26
Dima Avatar answered Sep 18 '22 13:09

Dima