PHP实现显示照片exif信息的方法
程序员文章站
2022-06-13 19:43:00
php编程可实现显示照片exif信息,显示图片中缩略图效果,其代码如下:
/**
* 获取图象信息的函数
* 一个全面获取图象信息的函数...
php编程可实现显示照片exif信息,显示图片中缩略图效果,其代码如下:
<? /** * 获取图象信息的函数 * 一个全面获取图象信息的函数 * @access public * @param string $img 图片路径 * @return array */ function getimageinfoval($imageinfo,$val_arr) { $infoval = "未知"; foreach($val_arr as $name=>$val) { if ($name==$imageinfo) { $infoval = &$val; break; } } return $infoval; } function getimageinfo($img) { $imgtype = array("", "gif", "jpg", "png", "swf", "psd", "bmp", "tiff(intel byte order)", "tiff(motorola byte order)", "jpc", "jp2", "jpx", "jb2", "swc", "iff", "wbmp", "xbm"); $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"); $resolutionunit = array("", "", "英寸", "厘米"); $ycbcrpositioning = array("", "the center of pixel array", "the datum point"); $exposureprogram = array("未定义", "手动", "标准程序", "光圈先决", "快门先决", "景深先决", "运动模式", "肖像模式", "风景模式"); $meteringmode_arr = array( "0" => "未知", "1" => "平均", "2" => "*重点平均测光", "3" => "点测", "4" => "分区", "5" => "评估", "6" => "局部", "255" => "其他" ); $lightsource_arr = array( "0" => "未知", "1" => "日光", "2" => "荧光灯", "3" => "钨丝灯", "10" => "闪光灯", "17" => "标准灯光a", "18" => "标准灯光b", "19" => "标准灯光c", "20" => "d55", "21" => "d65", "22" => "d75", "255" => "其他" ); $flash_arr = array( "0" => "flash did not fire", "1" => "flash fired", "5" => "flash fired but strobe return light not detected", "7" => "flash fired and strobe return light detected", ); $exif = exif_read_data ($img,"ifd0"); if ($exif===false) { $new_img_info = array ("文件信息" => "没有图片exif信息"); } else { $exif = exif_read_data ($img,0,true); $new_img_info = array ( "文件信息" => "-----------------------------", "文件名" => $exif[file][filename], "文件类型" => $imgtype[$exif[file][filetype]], "文件格式" => $exif[file][mimetype], "文件大小" => $exif[file][filesize], "时间戳" => date("y-m-d h:i:s",$exif[file][filedatetime]), "图像信息" => "-----------------------------", "图片说明" => $exif[ifd0][imagedescription], "制造商" => $exif[ifd0][make], "型号" => $exif[ifd0][model], "方向" => $orientation[$exif[ifd0][orientation]], "水平分辨率" => $exif[ifd0][xresolution].$resolutionunit[$exif[ifd0][resolutionunit]], "垂直分辨率" => $exif[ifd0][yresolution].$resolutionunit[$exif[ifd0][resolutionunit]], "创建软件" => $exif[ifd0][software], "修改时间" => $exif[ifd0][datetime], "作者" => $exif[ifd0][artist], "ycbcr位置控制" => $ycbcrpositioning[$exif[ifd0][ycbcrpositioning]], "版权" => $exif[ifd0][copyright], "摄影版权" => $exif[computed][copyright.photographer], "编辑版权" => $exif[computed][copyright.editor], "拍摄信息" => "-----------------------------", "exif版本" => $exif[exif][exifversion], "flashpix版本" => "ver. ".number_format($exif[exif][flashpixversion]/100,2), "拍摄时间" => $exif[exif][datetimeoriginal], "数字化时间" => $exif[exif][datetimedigitized], "拍摄分辨率高" => $exif[computed][height], "拍摄分辨率宽" => $exif[computed][width], /* the actual aperture value of lens when the image was taken. unit is apex. to convert this value to ordinary f-number(f-stop), calculate this value's power of root 2 (=1.4142). for example, if the aperturevalue is '5', f-number is pow(1.41425,5) = f5.6. */ "光圈" => $exif[exif][aperturevalue], "快门速度" => $exif[exif][shutterspeedvalue], "快门光圈" => $exif[computed][aperturefnumber], "最大光圈值" => "f".$exif[exif][maxaperturevalue], "曝光时间" => $exif[exif][exposuretime], "f-number" => $exif[exif][fnumber], "测光模式" => getimageinfoval($exif[exif][meteringmode],$meteringmode_arr), "光源" => getimageinfoval($exif[exif][lightsource], $lightsource_arr), "闪光灯" => getimageinfoval($exif[exif][flash], $flash_arr), "曝光模式" => ($exif[exif][exposuremode]==1?"手动":"自动"), "白平衡" => ($exif[exif][whitebalance]==1?"手动":"自动"), "曝光程序" => $exposureprogram[$exif[exif][exposureprogram]], /* brightness of taken subject, unit is apex. to calculate exposure(ev) from brigtnessvalue(bv), you must add sensitivityvalue(sv). ev=bv+sv sv=log((isospeedrating/3.125),2) iso100:sv=5, iso200:sv=6, iso400:sv=7, iso125:sv=5.32. */ "曝光补偿" => $exif[exif][exposurebiasvalue]."ev", "iso感光度" => $exif[exif][isospeedratings], "分量配置" => (bin2hex($exif[exif][componentsconfiguration])=="01020300"?"ycbcr":"rgb"),//'0x04,0x05,0x06,0x00'="rgb" '0x01,0x02,0x03,0x00'="ycbcr" "图像压缩率" => $exif[exif][compressedbitsperpixel]."bits/pixel", "对焦距离" => $exif[computed][focusdistance]."m", "焦距" => $exif[exif][focallength]."mm", "等价35mm焦距" => $exif[exif][focallengthin35mmfilm]."mm", /* 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). '0x41,0x53,0x43,0x49,0x49,0x00,0x00,0x00':ascii '0x4a,0x49,0x53,0x00,0x00,0x00,0x00,0x00':jis '0x55,0x4e,0x49,0x43,0x4f,0x44,0x45,0x00':unicode '0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00':undefined */ "用户注释编码" => $exif[computed][usercommentencoding], "用户注释" => $exif[computed][usercomment], "色彩空间" => ($exif[exif][colorspace]==1?"srgb":"uncalibrated"), "exif图像宽度" => $exif[exif][exifimagelength], "exif图像高度" => $exif[exif][exifimagewidth], "文件来源" => (bin2hex($exif[exif][filesource])==0x03?"digital still camera":"unknown"), "场景类型" => (bin2hex($exif[exif][scenetype])==0x01?"a directly photographed image":"unknown"), "缩略图文件格式" => $exif[computed][thumbnail.filetype], "缩略图mime格式" => $exif[computed][thumbnail.mimetype] ); } return $new_img_info; } $innerhtml = ""; $exif = getimageinfo($_get['img']); $innerhtml .= "<table>"; foreach($exif as $name=>$val) { $innerhtml .= "<tr><td>{$name}</td><td>{$val}</td></tr>"; } $innerhtml .= "<tr><td colspan=\"2\">"; if ($_get['img']) { $image = exif_thumbnail($_get['img']); } else { $image = false; } if ($image!==false) { $innerhtml .= "<img src=\"thumbnail.php?img=".$_get['img']."\">"; } else { // no thumbnail available, handle the error here $innerhtml .= "no thumbnail available"; } $innerhtml .= "</td></tr></table>"; ?> <html> <head> <title>图片信息</title> <meta http-equiv="content-type" content="text/html; charset=??????"> </head> <body> <script> <!-- //初始化内容值 parent.followtd<?=$_get['r_id'];?>.innerhtml='<?=$innerhtml;?>'; //已读取 parent.document.images.followimg<?=$_get['r_id'];?>.loaded='yes'; --> </script> </body> </html>
上一篇: Vue完整项目构建(进阶篇)
下一篇: 影响个人网站发展的几大因素