Getting "Date taken" of the photo instead of "Modified date" with PHP exif_read_data

I get the creation date from the photo using the exif_read_data PHP function (see code below). Dates obtained from photos that have not been changed return "Date taken." Those that have been changed - "Date changed." Is there a way to get the date when the photo was taken, ignoring the "Date modified" field?

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

Thanks.

Edit: I think $ exif_data ['DateTime'] uses the first available date field. Since the unchanged images had the same meaning for “Date Modified” and “Date Taken”, in my case it always retrieved “Date Modified”.

+8
php image exif
source share
5 answers

Ok, I know this is a little late since 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 on how to get the answer, therefore I am sharing this. Write a php script to print the exif_read_data array and you will find all kinds of interesting information. This (below) was printed on the command line on 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 this helps 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
 )
+11
source share

The solution is simpler than I thought. I meant the wrong tag. To get the date of use, use:

$ exif_data ['Fractions of seconds of the original time'];

+6
source share
 echo "test1.jpg:<br />\n"; $exif = exif_read_data('tests/test1.jpg', 'IFD0'); echo $exif===false ? "No header data found.<br />\n" : "Image contains headers<br />\n"; $exif = exif_read_data('tests/test2.jpg', 0, true); echo "test2.jpg:<br />\n"; foreach ($exif as $key => $section) { foreach ($section as $name => $val) { echo "$key.$name: $val<br />\n"; } } 

displays

 test1.jpg: No header data found. test2.jpg: FILE.FileName: test2.jpg FILE.FileDateTime: 1017666176 FILE.FileSize: 1240 FILE.FileType: 2 FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, COMMENT COMPUTED.html: width="1" height="1" COMPUTED.Height: 1 COMPUTED.Width: 1 COMPUTED.IsColor: 1 COMPUTED.ByteOrderMotorola: 1 COMPUTED.UserComment: Exif test image. COMPUTED.UserCommentEncoding: ASCII COMPUTED.Copyright: Photo (c) M.Boerger, Edited by M.Boerger. COMPUTED.Copyright.Photographer: Photo (c) M.Boerger COMPUTED.Copyright.Editor: Edited by M.Boerger. IFD0.Copyright: Photo (c) M.Boerger IFD0.UserComment: ASCII THUMBNAIL.JPEGInterchangeFormat: 134 THUMBNAIL.JPEGInterchangeFormatLength: 523 COMMENT.0: Comment #1. COMMENT.1: Comment #2. COMMENT.2: Comment #3end THUMBNAIL.JPEGInterchangeFormat: 134 THUMBNAIL.Thumbnail.Height: 1 THUMBNAIL.Thumbnail.Height: 1 

source http://php.net/manual/en/function.exif-read-data.php

+2
source share

In the image file directory (IFD), there is DateTime information in which the data structure in EXIF is repeated . To get the shooting date and present the object as the source php DateTime , you should get it from the right IFD section:

 <?php $filename = "/path/to/your/image.jpg"; $exifData = exif_read_data( $filename, 'IFD0'); $takenDate = NULL; if( $exifData !== FALSE ) { if( array_key_exists('DateTime', $exifData ) ) { $takenDate = new DateTime( $exifData['DateTime'] ); } else { // No DateTime field available } } else { // No exif data available } 

After that, you can simply check the exif DateTime data:

 is_null( $takenDate ); 
+2
source share

Not sure where you got the information, but exif information depends on the image or the captured device. Even if its modified exif may be alternating

Example

 array (size=7) 'FileName' => string 'img.jpg' (length=7) 'FileDateTime' => int 1332747844 'FileSize' => int 22569 'FileType' => int 2 'MimeType' => string 'image/jpeg' (length=10) 'SectionsFound' => string 'IFD0' (length=4) 'COMPUTED' => array (size=5) 'html' => string 'width="338" height="506"' (length=24) 'Height' => int 506 'Width' => int 338 'IsColor' => int 1 'ByteOrderMotorola' => int 0 

This is valid exif information, but does not include

  • Datetime
  • Datetaken
  • Datemodified
  • Fractions of seconds of the original time
  • Fractions of seconds of time

You really need to rethink your strategy and work with FileDateTime , this is the only information that is always present

0
source share

All Articles