Heim  >  Artikel  >  Backend-Entwicklung  >  PHP获取图片exif属性信息的方法

PHP获取图片exif属性信息的方法

WBOY
WBOYOriginal
2016-06-20 13:04:231665Durchsuche

PHP获取图片exif属性信息的方法

<?php<br />/**<br />* 获取图象信息的函数<br />*<br />* 一个全面获取图象信息的函数<br />*<br />* @access public<br />* @param string $img 图片路径<br />* @return array<br />*/<br />function GetImageInfoVal($ImageInfo,$val_arr) {<br />    $InfoVal = "未知";<br />    foreach($val_arr as $name=>$val) {<br />    if ($name==$ImageInfo) {<br />    $InfoVal = &$val;<br />    break;<br />    }<br />    }<br />    return $InfoVal;<br />}<br />function GetImageInfo($img) {<br />    <br /> <br />    <br />    $imgtype = array("", "GIF", "JPG", "PNG", "SWF", "PSD", "BMP", "TIFF(intel byte order)", "TIFF(motorola byte order)", "JPC", "JP2", "JPX", "JB2", "SWC", "IFF", "WBMP", "XBM");<br />    $Orientation = array("", "top left side", "top right side", "bottom right side", "bottom left side", "left side top", "right side top", "right side bottom", "left side bottom");<br />    $ResolutionUnit = array("", "", "英寸", "厘米");<br />    $YCbCrPositioning = array("", "the center of pixel array", "the datum point");<br />    $ExposureProgram = array("未定义", "手动", "标准程序", "光圈先决", "快门先决", "景深先决", "运动模式", "肖像模式", "风景模式");<br />    $MeteringMode_arr = array(<br />    "0" => "未知",<br />    "1" => "平均",<br />    "2" => "中央重点平均测光",<br />    "3" => "点测",<br />    "4" => "分区",<br />    "5" => "评估",<br />    "6" => "局部",<br />    "255" => "其他"<br />    );<br />    $Lightsource_arr = array(<br />    "0" => "未知",<br />    "1" => "日光",<br />    "2" => "荧光灯",<br />    "3" => "钨丝灯",<br />    "10" => "闪光灯",<br />    "17" => "标准灯光A",<br />    "18" => "标准灯光B",<br />    "19" => "标准灯光C",<br />    "20" => "D55",<br />    "21" => "D65",<br />    "22" => "D75",<br />    "255" => "其他"<br />    );<br />    $Flash_arr = array(<br />    "0" => "flash did not fire",<br />    "1" => "flash fired",<br />    "5" => "flash fired but strobe return light not detected",<br />    "7" => "flash fired and strobe return light detected",<br />    );<br />    <br />    $exif = exif_read_data ($img,"IFD0");<br />    if ($exif===false) {<br />    $new_img_info = array ("文件信息" => "没有图片EXIF信息");<br />    }<br />    else<br />    {<br />    $exif = exif_read_data ($img,0,true);<br />    $new_img_info = array (<br />    "文件信息" => "-----------------------------",<br />    "文件名" => $exif[FILE][FileName],<br />    "文件类型" => $imgtype[$exif[FILE][FileType]],<br />    "文件格式" => $exif[FILE][MimeType],<br />    "文件大小" => $exif[FILE][FileSize],<br />    "时间戳" => date("Y-m-d H:i:s",$exif[FILE][FileDateTime]),<br />    "图像信息" => "-----------------------------",<br />    "图片说明" => $exif[IFD0][ImageDescription],<br />    "制造商" => $exif[IFD0][Make],<br />    "型号" => $exif[IFD0][Model],<br />    "方向" => $Orientation[$exif[IFD0][Orientation]],<br />    "水平分辨率" => $exif[IFD0][XResolution].$ResolutionUnit[$exif[IFD0][ResolutionUnit]],<br />    "垂直分辨率" => $exif[IFD0][YResolution].$ResolutionUnit[$exif[IFD0][ResolutionUnit]],<br />    "创建软件" => $exif[IFD0][Software],<br />    "修改时间" => $exif[IFD0][DateTime],<br />    "作者" => $exif[IFD0][Artist],<br />    "YCbCr位置控制" => $YCbCrPositioning[$exif[IFD0][YCbCrPositioning]],<br />    "版权" => $exif[IFD0][Copyright],<br />    "摄影版权" => $exif[COMPUTED][Copyright.Photographer],<br />    "编辑版权" => $exif[COMPUTED][Copyright.Editor],<br />    "拍摄信息" => "-----------------------------",<br />    "Exif版本" => $exif[EXIF][ExifVersion],<br />    "FlashPix版本" => "Ver. ".number_format($exif[EXIF][FlashPixVersion]/100,2),<br />    "拍摄时间" => $exif[EXIF][DateTimeOriginal],<br />    "数字化时间" => $exif[EXIF][DateTimeDigitized],<br />    "拍摄分辨率高" => $exif[COMPUTED][Height],<br />    "拍摄分辨率宽" => $exif[COMPUTED][Width],<br />    /*<br />    The actual aperture value of lens when the image was taken.<br />    Unit is APEX.<br />    To convert this value to ordinary F-number(F-stop),<br />    calculate this value's power of root 2 (=1.4142).<br />    For example, if the ApertureValue is '5', F-number is pow(1.41425,5) = F5.6.<br />    */<br />    "光圈" => $exif[EXIF][ApertureValue],<br />    "快门速度" => $exif[EXIF][ShutterSpeedValue],<br />    "快门光圈" => $exif[COMPUTED][ApertureFNumber],<br />    "最大光圈值" => "F".$exif[EXIF][MaxApertureValue],<br />    "曝光时间" => $exif[EXIF][ExposureTime],<br />    "F-Number" => $exif[EXIF][FNumber],<br />    "测光模式" => GetImageInfoVal($exif[EXIF][MeteringMode],$MeteringMode_arr),<br />    "光源" => GetImageInfoVal($exif[EXIF][LightSource], $Lightsource_arr),<br />    "闪光灯" => GetImageInfoVal($exif[EXIF][Flash], $Flash_arr),<br />    "曝光模式" => ($exif[EXIF][ExposureMode]==1?"手动":"自动"),<br />    "白平衡" => ($exif[EXIF][WhiteBalance]==1?"手动":"自动"),<br />    "曝光程序" => $ExposureProgram[$exif[EXIF][ExposureProgram]],<br />    /*<br />    Brightness of taken subject, unit is APEX. To calculate Exposure(Ev) from BrigtnessValue(Bv), you must add SensitivityValue(Sv).<br />    Ev=Bv+Sv Sv=log((ISOSpeedRating/3.125),2)<br />    ISO100:Sv=5, ISO200:Sv=6, ISO400:Sv=7, ISO125:Sv=5.32. <br />    */<br />    "曝光补偿" => $exif[EXIF][ExposureBiasValue]."EV",<br />    "ISO感光度" => $exif[EXIF][ISOSpeedRatings],<br />    "分量配置" => (bin2hex($exif[EXIF][ComponentsConfiguration])=="01020300"?"YCbCr":"RGB"),//'0x04,0x05,0x06,0x00'="RGB" '0x01,0x02,0x03,0x00'="YCbCr"<br />    "图像压缩率" => $exif[EXIF][CompressedBitsPerPixel]."Bits/Pixel",<br />    "对焦距离" => $exif[COMPUTED][FocusDistance]."m",<br />    "焦距" => $exif[EXIF][FocalLength]."mm",<br />    "等价35mm焦距" => $exif[EXIF][FocalLengthIn35mmFilm]."mm",<br />    /*<br />    Stores user comment. This tag allows to use two-byte character code or unicode. First 8 bytes describe the character code. 'JIS' is a Japanese character code (known as Kanji).<br />    '0x41,0x53,0x43,0x49,0x49,0x00,0x00,0x00':ASCII<br />    '0x4a,0x49,0x53,0x00,0x00,0x00,0x00,0x00':JIS<br />    '0x55,0x4e,0x49,0x43,0x4f,0x44,0x45,0x00':Unicode<br />    '0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00':Undefined<br />    */<br />    "用户注释编码" => $exif[COMPUTED][UserCommentEncoding],<br />    "用户注释" => $exif[COMPUTED][UserComment],<br />    "色彩空间" => ($exif[EXIF][ColorSpace]==1?"sRGB":"Uncalibrated"),<br />    "Exif图像宽度" => $exif[EXIF][ExifImageLength],<br />    "Exif图像高度" => $exif[EXIF][ExifImageWidth],<br />    "文件来源" => (bin2hex($exif[EXIF][FileSource])==0x03?"digital still camera":"unknown"),<br />    "场景类型" => (bin2hex($exif[EXIF][SceneType])==0x01?"A directly photographed image":"unknown"),<br />    "缩略图文件格式" => $exif[COMPUTED][Thumbnail.FileType],<br />    "缩略图Mime格式" => $exif[COMPUTED][Thumbnail.MimeType]<br />    );<br />    }<br />    return $new_img_info;<br />}<br /> <br />$innerhtml = "";<br />$exif = GetImageInfo($_GET['img']);<br />$innerhtml .= "<TABLE>";<br /> <br />foreach($exif as $name=>$val) {<br />    $innerhtml .= "<TR><TD>{$name}</TD><TD>{$val}</TD></TR>";<br />}<br /> <br />$innerhtml .= "<TR><TD colspan=\"2\">";<br />if ($_GET['img']) {<br />    $image = exif_thumbnail($_GET['img']);<br />} else {<br />    $image = false;<br />}<br />if ($image!==false) {<br />    $innerhtml .= "<img  src=\"thumbnail.php?img=".$_GET['img']."\" alt="PHP获取图片exif属性信息的方法" >";<br />} else {<br />    // no thumbnail available, handle the error here<br />    $innerhtml .= "No thumbnail available";<br />}<br /> <br />$innerhtml .= "</TD></TR></TABLE>";<br />?><br /><html><br /><head> <br /><title>图片信息</title><br /><meta http-equiv="Content-Type" content="text/html; charset=??????"><br /></head><br /><body><br /><SCRIPT><br /><!--<br />//初始化内容值<br />parent.followTd<?=$_GET['r_id'];?>.innerHTML='<?=$innerhtml;?>';<br />//已读取<br />parent.document.images.followImg<?=$_GET['r_id'];?>.loaded='yes';<br />--><br /></SCRIPT><br /></body><br /></html>


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:php中session和cookie的区别Nächster Artikel:PHP购物车类代码