我正在使用exif_read_data PHP函数从照片中检索创建日期(请参阅下面的代码。)从未经修改的照片中检索的日期返回“Date Taken”。那些已被修改的 - “修改日期”。有没有办法让照片拍摄日期,忽略“修改日期”字段?
$exif_data = exif_read_data ($filename);
if (!empty($exif_data['DateTime'])) {
$exif_date = $exif_data['DateTime'];
}
谢谢。
编辑:我认为$ exif_data ['DateTime']使用第一个可用日期字段。由于未修改的图像具有相同的“修改日期”和“采取日期”的值,因此在我的情况下总是检索“修改日期”。
答案 0 :(得分:12)
好吧,我知道这个问题有点晚了,因为这个问题是在一年前发布的,但是我发布这个答案是因为我有同样的问题而且我的丈夫向我展示了一两个关于如何得到答案的技巧,所以我正在分享它。 编写一个php脚本来打印出exif_read_data数组,你会发现各种有趣的信息。这个(下面)使用print_r()在命令行上打印到stdout。如果向下滚动,您将看到两个非常有趣的键: [DateTime] => 2011:06:21 17:50:57和[DateTimeOriginal] => 2011:06:04 08:56:22
我希望这些能帮助你得到你需要的东西。
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 )
答案 1 :(得分:8)
我认为解决方案更容易。我指的是一个错误的标签。要获取日期,请使用:
$ exif_data ['原始日期时间'];
答案 2 :(得分:2)
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";
}
}
将输出
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
答案 3 :(得分:2)
DateTime信息存在于图像文件目录(IFD)中,它是EXIF数据中的重复数据结构。要获取照片的日期并表示为本机php DateTime对象,您需要从右IFD部分获取它:
<?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
}
之后,您可以简单地验证exif DateTime数据:
is_null( $takenDate );
答案 4 :(得分:0)
我不确定您获取信息的位置,但exif信息取决于图像或捕获的设备。即使它修改了exif也可以条纹
示例
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
这是有效的exif
信息,但不包括
您真的需要重新考虑您的策略,并与FileDateTime
合作,这是唯一可以识别的信息