首页 > 开发 > PHP > 正文

整理显示照片exif信息

2024-05-04 22:56:10
字体:
来源:转载
供稿:网友


中文方式显示照片exif信息,显示图片中所略图

这东西除了一些php论坛简单显示三两信息,别人的lb5000论坛上看到过显示,asp的也有不过很久没接触看着晕。

不想重复劳动,搜过google,除了asp没找到其他开源的显示exif的,所以整理出来或许有用。

没什么技术含量,基本只是汉化和资料整理的工作,以下代码为主要部分,所有文件在压缩包内,可以广泛用于相册和论坛显示图片信息的插件,希望熟悉相关知识的朋友找找bug或者加以优化。

目前应该缺不少信息,如果单单使用应该足够了。

——————————————————
看到过别人传过来的照片里面有缩略图,photoshop做的,但是不知道怎么加进去,有人知道么

缩略图可以显示:)


php代码:--------------------------------------------------------------------------------

<?
/**
* 获取图象信息的函数
*
* 一个全面获取图象信息的函数
*
* @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>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表