Exif.class.php 7.84 KB
<?php
class Util_Image_Exif
{
    private $mImgType;
    private $mOrientation;
    private $mResolutionUnit;
    private $mYCbCrPositioning;
    private $mExposureProgram;
    private $mMeteringMode;
    private $mLightsource;
    private $mFlash;
    public function __construct()
    {
        $this->mImgType = array('', 'GIF', 'JPG', 'PNG', 'SWF', 
                                'PSD', 'BMP', 'TIFF(intel byte order)', 
                                'TIFF(motorola byte order)', 'JPC', 'JP2', 
                                'JPX', 'JB2', 'SWC', 'IFF', 'WBMP', 'XBM');
        $this->mOrientation = 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');
        $this->mResolutionUnit = array('', '', '英寸', '厘米');
        $this->mYCbCrPositioning = array('', 'the center of pixel array', 'the datum point');
        $this->mExposureProgram = array('未定义', '手动', '标准程序', '光圈先决',
                                         '快门先决', '景深先決', '运动模式',
                                         '肖像模式', '风景模式');
        $this->mMeteringMode =  array(
                                    '0' => '未知',
                                    '1' => '平均',
                                    '2' => '中央重点平均测光',
                                    '3' => '点测',
                                    '4' => '分区',
                                    '5' => '评估',
                                    '6' => '局部',
                                    '255' => '其他'
                                    );
        $this->mLightsource = array(
                                    '0' => '未知',
                                    '1' => '日光',
                                    '2' => '荧光灯',
                                    '3' => '钨丝灯',
                                    '10' => '闪光灯',
                                    '17' => '标准灯光A',
                                    '18' => '标准灯光B',
                                    '19' => '标准灯光C',
                                    '20' => 'D55',
                                    '21' => 'D65',
                                    '22' => 'D75',
                                    '255' => '其他'
                                    );
        $this->mFlash = 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',
                            );
    }
    
    /**
     * 获取图片信息
     * 
     * @param string $image
     * @return array
     */
    public function getImageInfo($image)
    {
        if(function_exists("exif_read_data"))
        {
             $exif = exif_read_data($image);
            if ($exif===false) 
            {
                $imgInfo = array ("文件信息" => "没有图片EXIF信息");
            }
            else
            {
                date_default_timezone_set("PRC");
                $imgInfo = array (
                '文件信息' => "-----------------------------",
                '文件名' => $exif['FileName'],
                '文件类型' => $this->mImgType[$exif['FileType']],
                '文件格式' => $exif['MimeType'],
                '文件大小' => $exif['FileSize'],
                '时间戳' => date("Y-m-d H:i:s",$exif['FileDateTime']),
                '图像信息' => "-----------------------------",
                '图片说明' => $exif['ImageDescription'],
                '制造商' => $exif['Make'],
                '型号' => $exif['Model'],
                '方向' => $this->mOrientation[$exif['Orientation']],
                '水平分辨率' => $exif['XResolution'].$this->mResolutionUnit[$exif['ResolutionUnit']],
                '垂直分辨率' => $exif['YResolution'].$this->mResolutionUnit[$exif['ResolutionUnit']],
                '创建软件' => $exif['Software'],
                '修改时间' => $exif['DateTime'],
                '作者' => $exif['Artist'],
                'YCbCr位置控制' => $this->mYCbCrPositioning[$exif['YCbCrPositioning']],
                '版权' => $exif['Copyright'],
                '摄影版权' => $exif['COMPUTED']['Copyright.Photographer'],
                '编辑版权' => $exif['COMPUTED']['Copyright.Editor'],
                '拍摄信息' => "-----------------------------",
                'Exif版本' => $exif['ExifVersion'],
                'FlashPix版本' => "Ver. ".number_format($exif['FlashPixVersion']/100,2),
                '拍摄时间' => $exif['DateTimeOriginal'],
                '数字化时间' => $exif['DateTimeDigitized'],
                '拍摄分辨率高' => $exif['COMPUTED']['Height'],
                '拍摄分辨率宽' => $exif['COMPUTED']['Width'],
                //镜头的实际光圈值拍摄图像
                '光圈' => $exif['ApertureValue'],
                '快门速度' => $exif['ShutterSpeedValue'],
                '快门光圈' => $exif['COMPUTED']['ApertureFNumber'],
                '最大光圈值' => "F".$exif['MaxApertureValue'],
                '曝光时间' => $exif['ExposureTime'],
                'F-Number' => $exif['FNumber'],
                '测光模式' => $this->getImageInfoVal($exif['MeteringMode'],$this->mMeteringMode),
                '光源' => $this->getImageInfoVal($exif['LightSource'], $this->mLightsource),
                '闪光灯' => $this->getImageInfoVal($exif['Flash'], $this->mFlash),
                '曝光模式' => ($exif['ExposureMode']==1?'手动':'自动'),
                '白平衡' => ($exif['WhiteBalance']==1?'手动':'自动'),
                '曝光程序' => $this->mExposureProgram[$exif['ExposureProgram']],
                //主体亮度
                '曝光补偿' => $exif['ExposureBiasValue'].'EV',
                'ISO感光度' => $exif['ISOSpeedRatings'],
                        //'0x04,0x05,0x06,0x00'="RGB" '0x01,0x02,0x03,0x00'="YCbCr"
                '分量配置' => (bin2hex($exif['ComponentsConfiguration'])=="01020300"?"YCbCr":"RGB"),
                '图像压缩率' => $exif['CompressedBitsPerPixel'].'Bits/Pixel',
                '对焦距离' => $exif['COMPUTED']['FocusDistance'].'m',
                '焦距' => $exif['FocalLength'].'mm',
                '等价35mm焦距' => $exif['FocalLengthIn35mmFilm'].'mm',
                //
                '用户注释编码' => $exif['COMPUTED']['UserCommentEncoding'],
                '用户注释' => $exif['COMPUTED']['UserComment'],
                '色彩空间' => ($exif['ColorSpace']==1?'sRGB':'Uncalibrated'),
                'Exif图像宽度' => $exif['ExifImageLength'],
                'Exif图像高度' => $exif['ExifImageWidth'],
                '文件来源' => (bin2hex($exif['FileSource'])==0x03?'digital still camera':'unknown'),
                '场景类型' => (bin2hex($exif['SceneType'])==0x01?'A directly photographed image':'unknown'),
                '缩略图文件格式' => $exif['COMPUTED']['Thumbnail.FileType'],
                '缩略图Mime格式' => $exif['COMPUTED']['Thumbnail.MimeType'],
                );
            }
            return $imgInfo;
        }
        else
        {
            return "函数不存在";
        }
    }
    private function getImageInfoVal($imageInfo,$val_arr)
    {
        $infoVal = "未知";
        foreach($val_arr as $name=>$val)
        {
            if ($name==$imageInfo)
            {
                $infoVal = &$val;
                break;
            }
        }
        return $infoVal;
    }

}