PHP使用exif_read_data获取目标图像上使用的相机

时间:2017-08-23 00:20:07

标签: php metadata

我试图在目标图像上使用PHP exif_read_data下面的代码返回代码返回图像所有可用的元数据,但我目前很困惑如何获取我需要的特定数据,这是MODEL用来拍照的相机,任何建议都会非常感谢!

<?php

$exif = exif_read_data('382.jpg', 'IFD0');
echo $exif===false ? "No header data found.<br />\n" : "Image contains headers<br />\n";

$exif = exif_read_data('382.jpg', 0, true);

foreach ($exif as $key => $section) {

    foreach ($section as $name => $val) {

        echo "$key.$name: $val<br />\n";

    }
}
?>

我的输出在下面。

Image contains headers
FILE.FileName: 382.jpg
FILE.FileDateTime: 1503356646
FILE.FileSize: 366174
FILE.FileType: 2
FILE.MimeType: image/jpeg
FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS, INTEROP, MAKERNOTE
COMPUTED.html: width="950" height="712"
COMPUTED.Height: 712
COMPUTED.Width: 950
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 1
COMPUTED.CCDWidth: 6mm
COMPUTED.ApertureFNumber: f/3.4
COMPUTED.UserComment:
COMPUTED.UserCommentEncoding: UNDEFINED
COMPUTED.Thumbnail.FileType: 2
COMPUTED.Thumbnail.MimeType: image/jpeg
IFD0.ImageDescription:
IFD0.Make: Canon
IFD0.Model: Canon PowerShot SX50 HS
IFD0.Orientation: 1
IFD0.XResolution: 180/1
IFD0.YResolution: 180/1
IFD0.ResolutionUnit: 2
IFD0.DateTime: 2015:03:24 13:15:55
IFD0.Artist:
IFD0.YCbCrPositioning: 2
IFD0.Copyright:
IFD0.Exif_IFD_Pointer: 268
IFD0.GPS_IFD_Pointer: 5016
THUMBNAIL.Compression: 6
THUMBNAIL.XResolution: 180/1
THUMBNAIL.YResolution: 180/1
THUMBNAIL.ResolutionUnit: 2
THUMBNAIL.JPEGInterchangeFormat: 5130
THUMBNAIL.JPEGInterchangeFormatLength: 8036

1 个答案:

答案 0 :(得分:2)

要使用密钥访问字典的值,只需执行$dict['key'],如果该值恰好是另一个字典,则可以继续$dict['key1']['key2']['key3'] ...

echo($exif['IFD0']['Model']);