您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP中利用EXIF函数集回显示单反照片的EXIF信息

2025/12/4 14:15:50发布31次查看
php中利用exif函数集来显示单反照片的exif信息
要成功做到能用exif函数显示单反exif信息需要一下几个不步骤:
1.修改php.ini的exif相关信息
2.继续修改php.ini信息,找到以下模块,将带exif的配置属性前的;号去掉,然后重启apache
3.验证php确实开启了exif模块成功,利用以下代码
如果看到显示下图,则表示成功开启了exif模块,这样我们就可以开始利用其函数集了
4.开始写相关类(或函数,是别人封装好的,我个人觉得这个合适),如下,大家可以自己自行修改其中代码以供自己使用
$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;
    }
5.写测试代码
$section) {
            echo $key.:.$section.;
    }
?>
6.结果如图所示
文件信息:-----------------------------文件名:test.jpg文件类型:jpg文件格式:image/jpeg文件大小:477883时间戳:2014-03-07 14:53:57图像信息:-----------------------------图片说明:sony dsc制造商:sony型号:dslr-a900方向:top left side水平分辨率:2400000/10000英寸垂直分辨率:2400000/10000英寸创建软件:adobe photoshop cs6 (windows)修改时间:2014:01:13 14:02:59作者:ycbcr位置控制:版权:摄影版权:编辑版权:拍摄信息:-----------------------------exif版本:0221flashpix版本:ver. 0.00拍摄时间:2014:01:10 12:06:40数字化时间:2014:01:10 12:06:40拍摄分辨率高:806拍摄分辨率宽:1210光圈:761471/100000快门速度:7965784/1000000快门光圈:f/14.0最大光圈值:f434/100曝光时间:1/250f-number:14/1测光模式:评估光源:未知闪光灯:未知曝光模式:自动白平衡:自动曝光程序:光圈先决曝光补偿:-7/10eviso感光度:100分量配置:rgb图像压缩率:bits/pixel对焦距离:m焦距:120/10mm等价35mm焦距:12mm用户注释编码:用户注释:色彩空间:uncalibratedexif图像宽度:4032exif图像高度:6048文件来源:digital still camera场景类型:a directly photographed image缩略图文件格式:缩略图mime格式:
至此,一个简单利用exif函数集来显示图片的exif信息的模块就出来了.
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product