‘InterOperability指数 ‘ = $infoAll[‘InterOperabilityIndex ‘]
首先解释一下什么是Exif。Exif是一种图象文件格局,它的数据存储与JPEG格局是完全不异的。实际上,Exif格局就是在JPEG格局头部插入了数码照片的信息,包孕拍摄时的光圈、快门、白平衡、ISO、焦距、日期时间等各类和拍摄条件以及相机品牌、型号、色彩编码、拍摄时录制的声音以及全球定位系统(GPS)、缩略图等。简单地说,Exif=JPEG+拍摄参数。因此,你可以操作任何可以检察JPEG文件的看图软件浏览Exif格局的照片,但并不是所有的图形措施都能措置惩罚惩罚Exif信息。
开启PHP模块
默认情况下,PHP读取图片Exif信息模块是不开启的,我们需要先开启这个模块。
开启Exif模块需要mbstring撑持,所以先安置mbstring(此处法式省略,和处事器的环境有关),然后安置exif模块(此处法式同样省略,和处事器的环境有关)。
在php.ini中添加模块,打开php.ini添加以下两行
extension = "mbstring.so"extension = "exif.so"并且确认extension_dir值与你安置模块时提示的Installingshared extensions值一致,生存php.ini,重启webserver
2.读取图片Exif信息
撑持读取exif信息的图片类型在phpinfo里已经写明了,只能是jpeg或者tiff类型,此中jpeg是常用类型,这就已经足够。
<?php /** * @Author: TonyLevid * @Copyright: TonyLevid.com * @Name: Image Exif Class * @Version: 0.0.1 * 欢迎列位测试,如有BUG,请到网站留言 * I‘m pleased if you are willing to test my Image Exif class,if bug exists,you can leave a message. **/ //error_reporting(0); 不想让用户看到错误如果存在bug header("content-type:text/html;charset=utf-8"); //如果在html页面已经设置编码,请删除此行 class imgExif{ public $imgPath; public $unitFlag; public $imgInfoAll; public $imgInfoAllCN; public $imgInfoCommon; public $imgInfoBrief; public $imgInfoAllCNUnit; /*结构函数,检测exif和mbstring模块是否开启*/ function __construct(){ extension_loaded(‘exif‘)&&extension_loaded(‘mbstring‘) or die(‘exif module was not loaded,please check it in php.ini<br>NOTICE:On Windows,php_mbstring.dll must be before php_exif.dll‘); } /*获取图片格局,返回图片格局信息 * 如果只获取图片格局信息,建议给与此要领 * * @param $imgPath(必填,字符串),图片路径,不成为url。 * @param $MimeOrExifOrExtension(可选,字符串),获取图片格局为Mime类型或Exif类型或图片类型文件后缀。 * 如果为字符串‘Mime‘,则获取Mime图片类型。 * 如果为字符串‘Exif‘,则获取Exif图片类型。 * 如果为字符串‘Extension‘,则获取图片类型的文件后缀。 * 如果填写参数异常或缺省,则默认获取Mime图片类型。 */ function getImgtype($imgPath,$MimeOrExifOrExtension = null){ $exifImgtype = array( ‘IMAGETYPE_GIF‘ => 1, ‘IMAGETYPE_JPEG‘ => 2, ‘IMAGETYPE_PNG‘ => 3, ‘IMAGETYPE_SWF‘ => 4, ‘IMAGETYPE_PSD‘ => 5, ‘IMAGETYPE_BMP‘ => 6, ‘IMAGETYPE_TIFF_II‘ => 7, //(Intel 字节挨次) ‘IMAGETYPE_TIFF_MM‘ => 8, //(Motorola 字节挨次) ‘IMAGETYPE_JPC‘ => 9, ‘IMAGETYPE_JP2‘ => 10, ‘IMAGETYPE_JPX‘ => 11, ‘IMAGETYPE_JB2‘ => 12, ‘IMAGETYPE_SWC‘ => 13, ‘IMAGETYPE_IFF‘ => 14, ‘IMAGETYPE_WBMP‘ => 15, ‘IMAGETYPE_XBM‘ => 16 ); $exifType = array_search(exif_imagetype($imgPath),$exifImgtype); $mimeType = image_type_to_mime_type(exif_imagetype($imgPath)); $extension = substr(image_type_to_extension(exif_imagetype($imgPath)),1); if($MimeOrExifOrExtension){ if($MimeOrExifOrExtension === ‘Mime‘){ return $mimeType; } elseif($MimeOrExifOrExtension === ‘Exif‘){ return $exifType; } elseif($MimeOrExifOrExtension === ‘Extension‘){ return $extension; } else{ return $mimeType; } } else{ return $mimeType; } } /*措置惩罚惩罚Exif信息*/ function imgInfo(){ $imgPath = $this->imgPath; $imgInfoAll = exif_read_data($imgPath,0,1); foreach($imgInfoAll as $section => $arrValue){ foreach($arrValue as $key => $value){ $infoAllKey[] = $key; $infoAllValue[] = $value; } } $infoAll = array_combine($infoAllKey,$infoAllValue); $translate = array( ‘FileName‘=>‘文件名‘, ‘FileDateTime‘ => ‘文件改削时间‘, ‘FileSize‘ => ‘文件巨细‘, ‘FileType‘ => ‘Exif文件类型‘, ‘MimeType‘ => ‘Mime文件类型‘, ‘SectionsFound‘ => ‘找到Sections‘, ‘html‘ => ‘html中图片宽高‘, ‘Height‘ => ‘图片高度‘, ‘Width‘ => ‘图片宽度‘, ‘IsColor‘ => ‘是否彩色‘, ‘ByteOrderMotorola‘ => ‘是否为Motorola字节挨次‘, ‘ApertureFNumber‘ => ‘光圈数‘, ‘Comments‘ => ‘作者注释‘, ‘Author‘ => ‘作者‘, ‘UserComment‘ => ‘用户注释‘, ‘UserCommentEncoding‘ => ‘用户注释编码‘, ‘Thumbnail.FileType‘ => ‘缩略图Exif文件类型‘, ‘Thumbnail.MimeType‘ => ‘缩略图Mime文件类型‘, ‘Make‘ => ‘制造商‘, ‘Model‘ => ‘型号‘, ‘Orientation‘ => ‘标的目的‘, ‘XResolution‘ => ‘程度辨别率‘, ‘YResolution‘ => ‘垂直辨别率‘, ‘ResolutionUnit‘ => ‘辨别率单位‘, ‘Software‘ => ‘创建软件‘, ‘DateTime‘ => ‘最后改削时间‘, ‘YCbCrPositioning‘ => ‘YCbCr位置控制‘, ‘Exif_IFD_Pointer‘ => ‘Exif图像IFD的指针‘, ‘Compression‘ => ‘压缩方法‘, ‘JPEGInterchangeFormat‘ => ‘JPEG SOI偏移‘, ‘JPEGInterchangeFormatLength‘ => ‘JPEG数据字节‘, ‘ExposureTime‘ => ‘曝光时间‘, ‘FNumber‘ => ‘焦距比数‘, ‘ExposureProgram‘ => ‘曝光措施‘, ‘ISOSpeedRatings‘ => ‘ISO感光度‘, ‘ExifVersion‘ => ‘Exif版本‘, ‘DateTimeOriginal‘ => ‘拍摄时间‘, ‘DateTimeDigitized‘ => ‘数字化时间‘, ‘ComponentsConfiguration‘ => ‘分量配置‘, ‘CompressedBitsPerPixel‘ => ‘图像压缩率‘, ‘ExposureBiasValue‘ => ‘曝光赔偿‘, ‘MaxApertureValue‘ => ‘最大光圈值‘, ‘MeteringMode‘ => ‘测光模式‘, ‘LightSource‘ => ‘光源‘, ‘Flash‘ => ‘闪光灯‘, ‘FocalLength‘ => ‘焦距‘, ‘SubSecTime‘ => ‘亚秒时间‘, ‘SubSecTimeOriginal‘ => ‘亚秒级拍摄时间‘, ‘SubSecTimeDigitized‘ => ‘亚秒级数字化时间‘, ‘FlashPixVersion‘ => ‘FlashPix版本‘, ‘ColorSpace‘ => ‘色彩空间‘, ‘ExifImageWidth‘ => ‘Exif图片宽度‘, ‘ExifImageLength‘ => ‘EXif图片高度‘, ‘InteroperabilityOffset‘ => ‘IFD格局数据偏移量‘, ‘SensingMethod‘ => ‘彩色区域传感器类型‘, ‘FileSource‘ => ‘图片像源‘, ‘SceneType‘ => ‘场景类型‘, ‘CFAPattern‘ => ‘滤波阵列图案‘, ‘CustomRendered‘ => ‘自界说图像措置惩罚惩罚‘, ‘ExposureMode‘ => ‘曝光模式‘, ‘WhiteBalance‘ => ‘白平衡‘, ‘DigitalZoomRatio‘ => ‘数位变焦倍率‘, ‘FocalLengthIn35mmFilm‘ => ‘等价35mm焦距‘, ‘SceneCaptureType‘ => ‘取景模式‘, ‘GainControl‘ => ‘增益控制‘, ‘Contrast‘ => ‘比拟度‘, ‘Saturation‘ => ‘饱和度‘, ‘Sharpness‘ => ‘清晰度‘, ‘SubjectDistanceRange‘ => ‘对焦距离‘, ‘InterOperabilityIndex‘ => ‘InterOperability指数‘, ‘InterOperabilityVersion‘ => ‘InterOperability版本‘ ); @$translate_unit = array( ‘文件名‘ => $infoAll[‘FileName‘], ‘文件改削时间‘ => date(‘Y:m:d H:i:s‘,$infoAll[‘FileDateTime‘]), ‘文件巨细‘ => round($infoAll[‘FileSize‘]/1024) . ‘kb‘, ‘Exif文件类型‘ => $this->getImgtype($imgPath,‘Exif‘), ‘Mime文件类型‘ => $infoAll[‘MimeType‘], ‘找到Sections‘ => $infoAll[‘SectionsFound‘], ‘html中图片宽高‘ => $infoAll[‘html‘], ‘图片高度‘ => $infoAll[‘Height‘] . ‘px‘, ‘图片宽度‘ => $infoAll[‘Width‘] . ‘px‘, ‘是否彩色‘ => $infoAll[‘IsColor‘] == 1 ? ‘是‘ : ‘否‘, ‘是否为Motorola字节挨次‘ => $infoAll[‘ByteOrderMotorola‘] == 1 ? ‘是‘ : ‘否‘, ‘光圈数‘ => $infoAll[‘ApertureFNumber‘], ‘作者注释‘ => $infoAll[‘Comments‘], ‘作者‘ => $infoAll[‘Author‘], ‘用户注释‘ => $infoAll[‘UserComment‘], ‘用户注释编码‘ => $infoAll[‘UserCommentEncoding‘], ‘缩略图Exif文件类型‘ => $this->getImgtype($imgPath,‘Exif‘), ‘缩略图Mime文件类型‘ => $infoAll[‘Thumbnail.MimeType‘], ‘制造商‘ => $infoAll[‘Make‘], ‘型号‘ => $infoAll[‘Model‘], ‘标的目的‘ => array_search($infoAll[‘Orientation‘],array( ‘top left side‘ => 1, ‘top right side‘ => 2, ‘bottom right side‘ => 3, ‘bottom left side‘ => 4, ‘left side top‘ => 5, ‘right side top‘ => 6, ‘right side bottom‘ => 7, ‘left side bottom‘ => 8 )), ‘程度辨别率‘ => $infoAll[‘XResolution‘], ‘垂直辨别率‘ => $infoAll[‘YResolution‘], ‘辨别率单位‘ => array_search($infoAll[‘ResolutionUnit‘],array( ‘无单位‘ => 1, ‘英寸‘ => 2, ‘厘米‘ => 3 )), ‘创建软件‘ => $infoAll[‘Software‘], ‘最后改削时间‘ => $infoAll[‘DateTime‘], ‘YCbCr位置控制‘ => $infoAll[‘YCbCrPositioning‘] == 1 ? ‘像素阵列的中心‘ : ‘基准点‘, ‘Exif图像IFD的指针‘ => $infoAll[‘Exif_IFD_Pointer‘], ‘压缩方法‘ => $infoAll[‘Compression‘] == 6 ? ‘jpeg压缩‘ : ‘无压缩‘, ‘JPEG SOI偏移