我们来读取一张图片的exif信息试试
$exif = getExif('a.jpg');
echo '
';
print_r($exif);
echo '
';执行结果:
Array
(
[FileName] => a.jpg
[FileDateTime] => 1361340032
[FileSize] => 69170
[FileType] => 2
[MimeType] => image/jpeg
[SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS, INTEROP
[COMPUTED] => Array
(
[html] => width="600" height="397"
[Height] => 397
[Width] => 600
[IsColor] => 1
[ByteOrderMotorola] => 1
[ApertureFNumber] => f/13.0
[FocusDistance] => 3.76m
[UserComment] =>
[UserCommentEncoding] => ASCII
[Copyright] =>
[Thumbnail.FileType] => 2
[Thumbnail.MimeType] => image/jpeg
)
[ImageWidth] => 4928
[ImageLength] => 3264
[BitsPerSample] => Array
(
[0] => 8
[1] => 8
[2] => 8
)
[PhotometricInterpretation] => 2
[Make] => NIKON CORPORATION
[Model] => NIKON D7000
[Orientation] => 1
[SamplesPerPixel] => 3
[XResolution] => 3000000/10000
[YResolution] => 3000000/10000
[ResolutionUnit] => 2
[Software] => Adobe Photoshop CS5 Windows
[DateTime] => 2013:02:18 20:50:46
[WhitePoint] => Array
(
[0] => 313/1000
[1] => 329/1000
)
[PrimaryChromaticities] => Array
(
[0] => 64/100
[1] => 33/100
[2] => 21/100
[3] => 71/100
[4] => 15/100
[5] => 6/100
)
[YCbCrCoefficients] => Array
(
[0] => 299/1000
[1] => 587/1000
[2] => 114/1000
)
[YCbCrPositioning] => 2
[Copyright] =>
[Exif_IFD_Pointer] => 500
[GPS_IFD_Pointer] => 1248
[THUMBNAIL] => Array
(
[Compression] => 6
[XResolution] => 72/1
[YResolution] => 72/1
[ResolutionUnit] => 2
[JPEGInterchangeFormat] => 1362
[JPEGInterchangeFormatLength] => 4784
)
[ExposureTime] => 40/10
[FNumber] => 130/10
[ExposureProgram] => 1
[ISOSpeedRatings] => 1000
[UndefinedTag:0x8830] => 2
[ExifVersion] => 0230
[DateTimeOriginal] => 2013:02:14 21:12:08
[DateTimeDigitized] => 2013:02:14 21:12:08
[ComponentsConfiguration] =>
[CompressedBitsPerPixel] => 4/1
[ShutterSpeedValue] => -2/1
[ApertureValue] => 7400879/1000000
[ExposureBiasValue] => 2/6
[MaxApertureValue] => 36/10
[SubjectDistance] => 376/100
[MeteringMode] => 3
[LightSource] => 0
[Flash] => 16
[FocalLength] => 180/10
[UserComment] => ASCII
[SubSecTime] => 10
[SubSecTimeOriginal] => 10
[SubSecTimeDigitized] => 10
[FlashPixVersion] => 0100
[ColorSpace] => 65535
[ExifImageWidth] => 600
[ExifImageLength] => 397
[InteroperabilityOffset] => 1216
[SensingMethod] => 2
[FileSource] =>
[SceneType] =>
[CFAPattern] =>
[CustomRendered] => 0
[ExposureMode] => 1
[WhiteBalance] => 0
[DigitalZoomRatio] => 1/1
[FocalLengthIn35mmFilm] => 27
[SceneCaptureType] => 0
[GainControl] => 2
[Contrast] => 0
[Saturation] => 0
[Sharpness] => 0
[SubjectDistanceRange] => 0
[UndefinedTag:0xA500] => 22/10
[GPSVersion] =>
[InterOperabilityIndex] => R03
[InterOperabilityVersion] => 0100
)
如果提示:
Fatal error: Call to undefined function exif_read_data() in /data0/htdocs/www/exif/index.php on line 2
则表示模块没有打开,可能是你配置哪一块没有配置好,重新配置就好。
从Exif信息读取结果中取出有用的信息
从以上的执行结果我们发现图片Exif很多,我们只需要从中过滤掉垃圾信息剩下有用的就好。本例就以常用的参数为前提写一个PHP函数。常用的参数包括快门,器材名称,光圈,感光度,焦距
/**
* 读取jpeg图片的Exif信息
* $img 为图片路径
*
* 琼台博客
*/
function getExif($img){
$exif = exif_read_data($img, 'IFD0');
return array (
'文件名' => $exif['FileName'],
'器材品牌' => $exif['Make'],
'器材' => $exif['Model'],
'快门' => $exif['ExposureTime'],
'光圈' => $exif['FNumber'],
'焦距' => $exif['FocalLength'],
'感光度' => $exif['ISOSpeedRatings']
);
}
读取照片
$exifInfo = getExif('a.jpg');
echo '
';
print_r($exifInfo);
echo '
';执行结果:
Array
(
[文件名] => 25556306.jpg
[器材品牌] => NIKON CORPORATION
[器材] => NIKON D3100
[快门] => 10/32000
[光圈] => 18/10
[焦距] => 350/10
[感光度] => 100
)
其它说明
图片的Exif值是可以通过相应工具修改的,所以使用程序读取图片的Exif值只能用做参考,不做真实依据。
感兴趣的朋友也可以访问在线读取Exif信息网站http://exif.cn玩玩
通过PHP模块读取的Exif信息偶尔会错,或者信息不全,这种情况下,我们可以通过第三方工具。然后利用php执行系统linux命令读取