PHP实现显示照片exif信息的方法


Posted in PHP onJuly 11, 2014

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>
PHP 相关文章推荐
php 随机生成10位字符代码
Mar 26 PHP
开源php中文分词系统SCWS安装和使用实例
Apr 11 PHP
PHP数字字符串左侧补0、字符串填充和自动补齐的几种方法
May 10 PHP
PHP使用CURL实现对带有验证码的网站进行模拟登录的方法
Jul 23 PHP
PHP中exec与system用法区别分析
Sep 22 PHP
封装ThinkPHP的一个文件上传方法实例
Oct 31 PHP
PHP通过API获取手机号码归属地
May 28 PHP
Zend Framework动作助手Url用法详解
Mar 05 PHP
php图片添加文字水印实现代码
Mar 15 PHP
PHP入门教程之字符串处理技巧总结(转换,过滤,解析,查找,截取,替换等)
Sep 11 PHP
php微信支付之公众号支付功能
May 30 PHP
Laravel 关联模型-关联新增和关联更新的方法
Oct 10 PHP
php中json_encode处理gbk与gb2312中文乱码问题的解决方法
Jul 10 #PHP
PHP5.3与5.5废弃与过期函数整理汇总
Jul 10 #PHP
ThinkPHP标签制作教程
Jul 10 #PHP
YII路径的用法总结
Jul 09 #PHP
YII实现分页的方法
Jul 09 #PHP
YII模块实现绑定二级域名的方法
Jul 09 #PHP
yii操作cookie实例简介
Jul 09 #PHP
You might like
如何使用纯PHP实现定时器任务(Timer)
2015/07/31 PHP
详解PHP实现执行定时任务
2015/12/21 PHP
详解WordPress中用于更新和获取用户选项数据的PHP函数
2016/03/08 PHP
php图片添加水印例子
2016/07/20 PHP
php 中self,this的区别和操作方法实例分析
2019/11/04 PHP
跨浏览器的设置innerHTML方法
2006/09/18 Javascript
jquery.cookie.js 操作cookie实现记住密码功能的实现代码
2011/04/27 Javascript
jQuery EasyUI API 中文文档 - Menu菜单
2011/10/03 Javascript
基于jQuery实现左右div自适应高度完全相同的代码
2012/08/09 Javascript
js Map List 遍历使用示例
2013/07/10 Javascript
JS读取XML文件示例代码
2013/11/15 Javascript
使用控制台破解百小度一个月只准改一次名字
2015/08/13 Javascript
jQuery实现的简单提示信息插件
2015/12/08 Javascript
JS中取二维数组中最大值的方法汇总
2016/04/17 Javascript
Node.js返回JSONP详解
2016/05/18 Javascript
javascript稀疏数组(sparse array)和密集数组用法分析
2016/12/28 Javascript
Bootstrap表格使用方法详解
2017/02/17 Javascript
微信小程序 获取javascript 里的数据
2017/08/17 Javascript
详解微信小程序获取当前时间及日期的方法
2019/04/28 Javascript
webpack3升级到webpack4遇到问题总结
2019/09/30 Javascript
解决iview table组件里的 固定列 表格不自适应的问题
2020/11/13 Javascript
python命令行参数sys.argv使用示例
2014/01/28 Python
一条命令解决mac版本python IDLE不能输入中文问题
2018/05/15 Python
Python求两个圆的交点坐标或三个圆的交点坐标方法
2018/11/07 Python
基于Python安装pyecharts所遇的问题及解决方法
2019/08/12 Python
Python实现进度条和时间预估的示例代码
2020/06/02 Python
瀑布模型都有哪些优缺点
2014/06/23 面试题
校领导推荐信
2013/11/01 职场文书
应届护士推荐信
2013/11/16 职场文书
人事主管岗位职责范本
2013/12/04 职场文书
专业幼师实习生自我鉴定范文
2013/12/08 职场文书
外语专业毕业生自荐信
2014/04/14 职场文书
领导干部“四风”问题批评与自我批评材料
2014/09/24 职场文书
建议书格式
2015/02/04 职场文书
2016党员学习心得体会范文
2016/01/23 职场文书
html原生table实现合并单元格以及合并表头的示例代码
2023/05/07 HTML / CSS