仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1891|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网站制作之显示照片exif信息PHP代码

[复制链接]
愤怒的大鸟 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:58:05 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
PHP的理解是新手最难迈过的一道门槛,不过你应该感到幸运的是PHP已经最大极限的为了新手而努力了,如果你学过其他的语言,也许会觉得PHP的确相当的简单,但是如果你之前什么都没学过,那么阿弥陀佛,硬着头皮琢磨吧。   中文体例显示照片EXIF信息,显示图片中所略图 这器材除一些php服装论坛复杂显示三两信息,他人的lb5000服装论坛上看到过显示,asp的也有不外好久没接触看着晕。
不想反复休息,搜过谷歌,除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>
兴趣可能会慢慢消亡,所以适当培养兴趣会激发自己无线的乐趣,有了乐趣,编程有啥难的。
愤怒的大鸟 该用户已被删除
沙发
 楼主| 发表于 2015-3-7 14:52:28 | 显示全部楼层
学习php的目的往往是为了开发动态网站,phper就业的要求也涵盖了很多。我大致总结为:精通php和mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-16 00:59

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表