zoukankan      html  css  js  c++  java
  • PHP中Imagick类的使用(转) 简单

    http://php.net/manual/en/book.imagick.php 类参考文档 
    PHP中Imagick类的使用 
    PHP中Imagick类,提供了比GD库函数更为方便和强大的图片处理功能。由于工作关系研究了一阵,略有收获,不敢独乐,特与大家分享。 
    使用Imagick类,需要PHP安装imagemagick扩展模块。

     

    <?php
    /**
     * 对比度处理
     * @param bool 	$type				表示增加或减少对比度,逻辑型,true:增加; false:减少
     * @param bool 	$apply				表示作用区域,逻辑型,true:局部作用; false:全局作用
     * @param string $src				原图片位置
     * @param string $dst				处理后的目标图片存储位置
     * @param int $w					当$apply为true,来确定区域坐标
     * @param int $h
     * @param int $x
     * @param int $y
     * @param bool $f
     */
    function contrast ($type, $apply, $src, $dst, $w = 0, $h = 0, $x = 0, $y = 0, 
    $f = true)
    {
        if ($type)
            $s = 9;
        else
            $s = 0;
        if ($f)
            $image = new Imagick($src);
        else
            $image = $src;
        if ($apply) {
            $region = $image->getImageRegion($w, $h, $x, $y);
            $region->contrastImage($s);
            $image->compositeImage($region, $region->getImageCompose(), $x, $y);
            $region->destroy();
        } else
            $image->contrastImage($s);
        $image->writeImage($dst);
        $image->destroy();
    }
    /*
    函数说明:将字母和数字生成png图片
    函数参数:
    $text:需要生成图片的文字,string型
    $color:文字颜色,string型
    $szie:文字大小,int型
    $font:字体,string型
    $type:返回类型,逻辑型,true:返回图片地址; false:返回图片资源
    $src:保存图片的地址,string型
    */
    function text ($text, $color, $size, $font, $type = false, $src = '')
    {
        $font = "include/font/" . $font . ".ttf";
        $draw = new ImagickDraw();
        $draw->setGravity(Imagick::GRAVITY_CENTER);
        $draw->setFont($font);
        $draw->setFontSize($size);
        $draw->setFillColor(new ImagickPixel($color));
        $im = new imagick();
        $properties = $im->queryFontMetrics($draw, $text);
        $im->newImage(intval($properties['textWidth'] + 5), 
        intval($properties['textHeight'] + 5), new ImagickPixel('transparent'));
        $im->setImageFormat('png');
        $im->annotateImage($draw, 0, 0, 0, $text);
        if ($type) {
            $im->writeImage($src);
            return $src;
        } else
            return $im;
    }
    /*
    函数说明:加水印
    函数参数:
    $text:水印文字,string型
    $color:文字颜色,string型
    $szie:文字大小,int型
    $font:字体,string型
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    $x,$y:水印位置,int型
    */
    function mark ($text, $color, $size, $font, $src, $dst, $x, $y)
    {
        $im = text($text, $color, $size, $font);
        $image = new Imagick($src);
        $image->compositeImage($im, Imagick::COMPOSITE_OVER, $x, $y);
        $image->writeImage($dst);
        $im->destroy();
        $image->destroy();
    }
    /*
    函数说明:模糊处理
    函数参数:
    $radius:模糊程度,int型
    $apply:表示作用区域,逻辑型,true:局部作用; false:全局作用
    $w,$h,$x,$y:当$apply为true,来确定区域坐标,int型
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    */
    function gaussianblur ($radius, $apply, $src, $dst, $x = 0, $y = 0, $w = 0, $h = 0)
    {
        if ($apply && $x == 0 && $y == 0 && $w == 0 && $h == 0)
            $apply = false;
        $image = new Imagick($src);
        if ($apply) {
            $region = $image->getImageRegion($w, $h, $x, $y);
            $region->blurImage($radius, $radius);
            $image->compositeImage($region, $region->getImageCompose(), $x, $y);
            $region->destroy();
        } else
            $image->blurImage($radius, $radius);
        $image->writeImage($dst);
        $image->destroy();
    }
    /*
    函数说明:锐化处理
    函数参数:
    $radius:锐化程度,int型
    $apply:表示作用区域,逻辑型,true:局部作用; false:全局作用
    $w,$h,$x,$y:当$apply为true,来确定区域坐标,int型
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    */
    function sharpen ($radius, $apply, $src, $dst, $x = 0, $y = 0, $w = 0, $h = 0)
    {
        if ($apply && $x == 0 && $y == 0 && $w == 0 && $h == 0)
            $apply = false;
        $image = new Imagick($src);
        if ($apply) {
            $region = $image->getImageRegion($w, $h, $x, $y);
            $region->sharpenImage($radius, $radius);
            $image->compositeImage($region, $region->getImageCompose(), $x, $y);
            $region->destroy();
        } else
            $image->sharpenImage($radius, $radius);
        $image->writeImage($dst);
        $image->destroy();
    }
    /*
    函数说明:突起效果
    函数参数:
    $raise:突起度,int型
    $apply:表示作用区域,逻辑型,true:局部作用; false:全局作用
    $w,$h,$x,$y:当$apply为true,来确定区域坐标,int型
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    */
    function raise ($raise, $apply, $src, $dst, $x = 0, $y = 0, $w = 0, $h = 0)
    {
        if ($apply && $x == 0 && $y == 0 && $w == 0 && $h == 0)
            $apply = false;
        $image = new Imagick($src);
        if ($apply) {
            if ($w > (2 * $raise) && $h > (2 * $raise)) {
                $region = $image->getImageRegion($w, $h, $x, $y);
                $region->raiseImage($raise, $raise, 0, 0, true);
                $image->compositeImage($region, $region->getImageCompose(), $x, $y);
                $region->destroy();
            }
        } else {
            $info = $image->getImageGeometry();
            if ($info["width"] > (2 * $raise) && $info["height"] > (2 * $raise)) {
                $image->raiseImage($raise, $raise, 0, 0, true);
            }
        }
        $image->writeImage($dst);
        $image->destroy();
    }
    /*
    函数说明:边框效果
    函数参数:
    $frame_边框宽度,int型
    $frame_height:边框宽度,int型
    $bevel:边框角度,int型
    $color:边框颜色,string型
    $apply:表示作用区域,逻辑型,true:局部作用; false:全局作用
    $w,$h,$x,$y:当$apply为true,来确定区域坐标,int型
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    */
    function frame ($frame_width, $frame_height, $bevel, $color, $apply, $src, $dst, 
    $x = 0, $y = 0, $w = 0, $h = 0)
    {
        if ($apply && $x == 0 && $y == 0 && $w == 0 && $h == 0)
            $apply = false;
        $image = new Imagick($src);
        $framecolor = new ImagickPixel($color);
        if ($apply) {
            $region = $image->getImageRegion($w, $h, $x, $y);
            $region->frameImage($framecolor, $frame_width, $frame_height, $bevel, 
            $bevel);
            $image->compositeImage($region, $region->getImageCompose(), $x, $y);
            $region->destroy();
        } else
            $image->frameImage($framecolor, $frame_width, $frame_height, $bevel, 
            $bevel);
        $image->writeImage($dst);
        $framecolor->destroy();
        $image->destroy();
    }
    /*
    函数说明:油画效果
    函数参数:
    $radius:油画效果参数
    $apply:表示作用区域,逻辑型,true:局部作用; false:全局作用
    $w,$h,$x,$y:当$apply为true,来确定区域坐标,int型
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    */
    function oilpaint ($radius, $apply, $src, $dst, $x = 0, $y = 0, $w = 0, $h = 0)
    {
        if ($apply && $x == 0 && $y == 0 && $w == 0 && $h == 0)
            $apply = false;
        $image = new Imagick($src);
        if ($apply) {
            $region = $image->getImageRegion($w, $h, $x, $y);
            $region->oilPaintImage($radius);
            $image->compositeImage($region, $region->getImageCompose(), $x, $y);
            $region->destroy();
        } else
            $image->oilPaintImage($radius);
        $image->writeImage($dst);
        $image->destroy();
    }
    /*
    函数说明:发散效果
    函数参数:
    $radius:发散效果参数
    $apply:表示作用区域,逻辑型,true:局部作用; false:全局作用
    $w,$h,$x,$y:当$apply为true,来确定区域坐标,int型
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    */
    function spread ($radius, $apply, $src, $dst, $x = 0, $y = 0, $w = 0, $h = 0)
    {
        if ($apply && $x == 0 && $y == 0 && $w == 0 && $h == 0)
            $apply = false;
        $image = new Imagick($src);
        if ($apply) {
            $region = $image->getImageRegion($w, $h, $x, $y);
            $region->spreadImage($radius);
            $image->compositeImage($region, $region->getImageCompose(), $x, $y);
            $region->destroy();
        } else
            $image->spreadImage($radius);
        $image->writeImage($dst);
        $image->destroy();
    }
    /*
    函数说明:倾斜效果
    参数说明:
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    $color:背景颜色,string型
    $angle:倾斜角度,int型
    */
    function polaroidEffect ($src, $dst, $color, $angle = 0)
    {
        if (abs($angle) != 15) {
            $srcs = array($src, $src, $src, $src);
            $bg = new ImagickDraw();
            $images = new Imagick($srcs);
            $format = $images->getImageFormat();
            $maxwidth = 0;
            $maxheight = 0;
            foreach ($images as $key => $im) {
                $im->setImageFormat("png");
                $im->setImageBackgroundColor(new ImagickPixel("black"));
                $angle = mt_rand(- 20, 20);
                if ($angle == 0)
                    $angle = - 1;
                $im->polaroidImage($bg, $angle);
                $info = $im->getImageGeometry();
                $maxwidth = max($maxwidth, $info["width"]);
                $maxheight = max($maxheight, $info["height"]);
            }
            $image = new Imagick();
            $image->newImage($maxwidth, $maxheight, new ImagickPixel($color));
            foreach ($images as $key => $im) {
                $image->compositeImage($im, $im->getImageCompose(), 0, 0);
            }
            $image->setImageFormat($format);
            $bg->destroy();
            $images->destroy();
        } else {
            $image = new Imagick($src);
            $format = $image->getImageFormat();
            $image->frameImage(new ImagickPixel("white"), 6, 6, 0, 0);
            $image->frameImage(new ImagickPixel("gray"), 1, 1, 0, 0);
            $image->setImageFormat("png");
            $shadow = $image->clone();
            $shadow->setImageBackgroundColor(new ImagickPixel("black"));
            $shadow->shadowImage(50, 3, 0, 0);
            $shadow->compositeImage($image, $image->getImageCompose(), 0, 0);
            $shadow->rotateImage(new ImagickPixel($color), $angle);
            $info = $shadow->getImageGeometry();
            $image->destroy();
            $image = new Imagick();
            $image->newImage($info["width"], $info["height"], 
            new ImagickPixel($color));
            $image->compositeImage($shadow, $shadow->getImageCompose(), 0, 0);
            $image->setImageFormat($format);
            $shadow->destroy();
        }
        $image->writeImage($dst);
        $image->destroy();
    }
    /*
    函数说明:生成手绘图片
    参数说明:
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    $color:画笔背景颜色,string型
    $size:画笔尺寸,int型
    $brushpath:画笔轨迹,array型
    */
    function brushpng ($src, $dst, $color, $size, $brushpath)
    {
        $image = new Imagick($src);
        $info = $image->getImageGeometry();
        $image->destroy();
        if (file_exists($dst))
            $image = new Imagick($dst);
        else {
            $image = new Imagick();
            $image->newImage($info["width"], $info["height"], "transparent", "png");
             //$image->setImageFormat("png");
        }
        $draw = new ImagickDraw();
        $pixel = new ImagickPixel();
        $pixel->setColor("transparent");
        $draw->setFillColor($pixel);
        $pixel->setColor($color);
        $draw->setStrokeColor($pixel);
        $draw->setStrokeWidth($size);
        $draw->setStrokeLineCap(imagick::LINECAP_ROUND);
        $draw->setStrokeLineJoin(imagick::LINEJOIN_ROUND);
        $draw->polyline($brushpath);
        $image->drawImage($draw);
        $image->writeImage($dst);
        $pixel->destroy();
        $draw->destroy();
        $image->destroy();
    }
    /*
    函数说明:合并图片
    参数说明:
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    $png:需要合并的png图片地址,string型
    */
    function dobrush ($src, $dst, $png)
    {
        $image = new Imagick($src);
        if (file_exists($png)) {
            $imagepng = new Imagick($png);
            $imagepng->setImageFormat("png");
            $image->compositeImage($imagepng, $imagepng->getImageCompose(), 0, 0);
            $imagepng->destroy();
        }
        $image->writeImage($dst);
        $image->destroy();
    }
    /*
    函数说明:旋转图片
    参数说明:
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    $angle:旋转角度,int型
    */
    function rotate ($src, $dst, $angle)
    {
        $image = new Imagick($src);
        $image->rotateImage(new ImagickPixel(), $angle);
        $image->writeImage($dst);
        $image->destroy();
    }
    /*
    函数说明:图片亮度处理
    参数说明:
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    $n:亮度比,float型
    $s_x,$s_y,$e_x,$e_y:起始点和结束点,int型
    $type:true表示存储图片,false表示返回处理后的Imagick对象
    */
    function brightness ($src, $dst, $n, $s_x = 0, $e_x = 0, $s_y = 0, $e_y = 0, 
    $type = true)
    {
        $im = new Imagick($src);
        $info = $im->getImageGeometry();
        $w = $info["width"];
        $h = $info["height"];
        $format = $im->getImageFormat();
        if ($s_x == 0 && $s_y == 0 && $e_x == 0 && $e_y == 0) {
            $e_x = $w;
            $e_y = $h;
        }
        $image = new Imagick();
        $image->newImage($w, $h, "transparent");
        $draw = new ImagickDraw();
        for ($x = 0; $x < $w; $x ++) {
            for ($y = 0; $y < $h; $y ++) {
                $p = $im->getImagePixelColor($x, $y);
                $rgb = $p->getColor();
                if ($x >= $s_x && $x < $e_x && $y >= $s_y && $y < $e_y) {
                    $rgb["r"] = $rgb["r"] + $rgb["r"] * $n;
                    $rgb["g"] = $rgb["g"] + $rgb["g"] * $n;
                    $rgb["b"] = $rgb["b"] + $rgb["b"] * $n;
                    $rgb["r"] = min(255, $rgb["r"]);
                    $rgb["r"] = max(0, $rgb["r"]);
                    $rgb["g"] = min(255, $rgb["g"]);
                    $rgb["g"] = max(0, $rgb["g"]);
                    $rgb["b"] = min(255, $rgb["b"]);
                    $rgb["b"] = max(0, $rgb["b"]);
                }
                $p->setColor("rgb({$rgb["r"]},{$rgb["g"]},{$rgb["b"]})");
                $draw->setFillColor($p);
                $draw->point($x, $y);
            }
        }
        $image->drawImage($draw);
        $image->setImageFormat($format);
        if ($type)
            $image->writeImage($dst);
        else
            return $image;
    }
    /*
    函数说明:图片灰度处理
    参数说明:
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    */
    function grayscale ($src, $dst, $apply, $x = 0, $y = 0, $w = 0, $h = 0)
    {
        if ($apply && $x == 0 && $y == 0 && $w == 0 && $h == 0)
            $apply = false;
        $image = new Imagick($src);
        if ($apply) {
            $region = $image->getImageRegion($w, $h, $x, $y);
            $clone = $region->clone();
            $clone = $region->fximage('p{0,0}');
            $region->compositeImage($clone, imagick::COMPOSITE_DIFFERENCE, 0, 0);
            $region->modulateImage(100, 0, 0);
            $image->compositeImage($region, $region->getImageCompose(), $x, $y);
        } else {
            $clone = $image->clone();
            $clone = $image->clone();
            $clone = $image->fximage('p{0,0}');
            $image->compositeImage($clone, imagick::COMPOSITE_DIFFERENCE, 0, 0);
            $image->modulateImage(100, 0, 0);
        }
        $image->writeImage($dst);
        $image->clear();
        $image->destroy();
    }
    /*
    函数说明:jpg质量压缩
    参数说明:
    $src:原图地址,string型
    $dst:保存图片的地址,string型
    $q:压缩比率
    此函数在安全模式下不能运行
    */
    function prequality ($src, $dst, $q)
    {
        exec("convert -quality {$q} {$src} {$dst}");
    }
    ?>

    引用地址: http://amazon0226.blog.163.com/blog/static/3190120420090713722831/

    Imagick函数库资料太少,能参考的就是PHP官方手册http://cn2.php.net/imagick,但是无详细示例介绍。下面简单写了个实例,找了手册很长时间才做出来的,希望对大家有帮助。

    原图http://test.studenthome.cn/imagick/b.jpg

    按要求缩小图片尺寸、增加半透明边框,读入exif信息,按指定要求显示在图片上。

    php生成的图片http://test.studenthome.cn/imagick/imagick4.php

    <?php
    $towidth = '500';
    $toheight = '700'; //设置图片调整大小时允许的最大宽度和高度
    $sourcefile = './b.jpg'; //定义一个图像文件路径
    //$image->writeImage('./b.jpg.bak'); //可以备份这个图片
    $myimage = new Imagick($sourcefile); //读入该图像文件
    $exifobject = my_exif($myimage); //自写函数,读取exif信息(拍摄数据),按自己的要求排列exif信息,返回对象
    //$myimage->setImageFormat('jpeg'); //把图片转为jpg格式
    $myimage->setCompressionQuality(100); //设置jpg压缩质量,1 - 100
    $myimage->enhanceImage(); //去噪点
    $sourcewidth = $myimage->getImageWidth(); //获取读入图像原始大小
    if ($sourcewidth > $towidth) {
        $myimage->scaleImage($towidth, $toheight, true); //调整图片大小
    }
    $myimage->raiseImage(8, 8, 0, 0, 1); //加半透明边框
    $resizewidth = $myimage->getImageWidth(); //读出调整之后的图片大小
    $resizeheight = $myimage->getImageHeight();
    $drawback = new ImagickDraw(); //实例化一个绘画对象,绘制半透明黑色背景给exif信息用
    $drawback->setFillColor(new ImagickPixel('#000000')); //设置填充颜色为黑色
    $drawback->setFillOpacity(0.6); //填充透明度为0.6,参数0.1-1,1为不透明
    $drawback->rectangle($resizewidth / 2 - 190, $resizeheight - 50, 
    $resizewidth / 2 + 190, $resizeheight - 12); //绘制矩形参数,分别为左上角x、y,右下角x、y
    $myimage->drawImage($drawback); //确认到image中绘制该矩形框
    $draw = new ImagickDraw(); //实例化一个绘画对象,绘制exif文本信息嵌入图片中
    $draw->setFont('./xianhei.ttf'); //设置文本字体,要求ttf或者ttc字体,可以绝对或者相对路径
    $draw->setFontSize(11); //设置字号
    $draw->setTextAlignment(2); //文字对齐方式,2为居中
    $draw->setFillColor('#FFFFFF'); //文字填充颜色
    $myimage->annotateImage($draw, $resizewidth / 2, $resizeheight - 39, 0, 
    $exifobject->row1); //绘制第一行文本,居中
    $myimage->annotateImage($draw, $resizewidth / 2, $resizeheight - 27, 0, 
    $exifobject->row2); //绘制第二行文本,居中
    $myimage->annotateImage($draw, $resizewidth / 2, $resizeheight - 15, 0, 
    $exifobject->row3); //绘制第三行文本,居中
    /* Output the image with headers */
    header('Content-type: image/jpeg'); //php文件输出mime类型为jpeg图片
    echo $myimage; //在当前php页面输出图片
    //$image->writeImage('./b.new.jpg'); //如果图片不需要在当前php程序中输出,使用写入图片到磁盘函数,上面的设置header也可以去除
    $myimage->clear();
    $myimage->destroy(); //释放资源
    //自写函数,读取exif信息,返回对象
    function my_exif ($myimage)
    {
        $exifArray = array('exif:Model' => '未知', 'exif:DateTimeOriginal' => '未知', 
        'exif:ExposureProgram' => '未知', 'exif:FNumber' => '0/10', 
        'exif:ExposureTime' => '0/10', 'exif:ISOSpeedRatings' => '未知', 
        'exif:MeteringMode' => '未知', 'exif:Flash' => '关闭闪光灯', 
        'exif:FocalLength' => '未知', 'exif:ExifImageWidth' => '未知', 
        'exif:ExifImageLength' => '未知'); //初始化部分信息,防止无法读取照片exif信息时运算发生错误
        $exifArray = $myimage->getImageProperties("exif:*"); //读取图片的exif信息,存入$exifArray数组
        //如果需要显示原数组可以使用print_r($exifArray);
        $r->row1 = '相机:' . $exifArray['exif:Model'];
        $r->row1 = $r->row1 . ' 拍摄时间:' . $exifArray['exif:DateTimeOriginal'];
        switch ($exifArray['exif:ExposureProgram']) {
            case 1:
                $exifArray['exif:ExposureProgram'] = "手动(M)";
                break; //Manual Control
            case 2:
                $exifArray['exif:ExposureProgram'] = "程序自动(P)";
                break; //Program Normal
            case 3:
                $exifArray['exif:ExposureProgram'] = "光圈优先(A,Av)";
                break; //Aperture Priority
            case 4:
                $exifArray['exif:ExposureProgram'] = "快门优先(S,Tv)";
                break; //Shutter Priority
            case 5:
                $exifArray['exif:ExposureProgram'] = "慢速快门";
                break; //Program Creative (Slow Program)
            case 6:
                $exifArray['exif:ExposureProgram'] = "运动模式";
                break; //Program Action(High-Speed Program)
            case 7:
                $exifArray['exif:ExposureProgram'] = "人像";
                break; //Portrait
            case 8:
                $exifArray['exif:ExposureProgram'] = "风景";
                break; //Landscape
            default:
                $exifArray['exif:ExposureProgram'] = "其它";
        }
        $r->row1 = $r->row1 . ' 模式:' . $exifArray['exif:ExposureProgram'];
        $exifArray['exif:FNumber'] = explode('/', $exifArray['exif:FNumber']);
        $exifArray['exif:FNumber'] = $exifArray['exif:FNumber'][0] /
         $exifArray['exif:FNumber'][1];
        $r->row2 = '光圈:F/' . $exifArray['exif:FNumber'];
        $exifArray['exif:ExposureTime'] = explode('/', 
        $exifArray['exif:ExposureTime']);
        if (($exifArray['exif:ExposureTime'][0] / $exifArray['exif:ExposureTime'][1]) >=
         1) {
            $exifArray['exif:ExposureTime'] = sprintf("%.1fs", 
            (float) $exifArray['exif:ExposureTime'][0] /
             $exifArray['exif:ExposureTime'][1]);
        } else {
            $exifArray['exif:ExposureTime'] = sprintf("1/%ds", 
            $exifArray['exif:ExposureTime'][1] / $exifArray['exif:ExposureTime'][0]);
        }
        $r->row2 = $r->row2 . ' 快门:' . $exifArray['exif:ExposureTime'];
        $r->row2 = $r->row2 . ' ISO:' . $exifArray['exif:ISOSpeedRatings'];
        $exifArray['exif:ExposureBiasValue'] = explode("/", 
        $exifArray['exif:ExposureBiasValue']);
        $exifArray['exif:ExposureBiasValue'] = sprintf("%1.1feV", 
        ((float) $exifArray['exif:ExposureBiasValue'][0] /
         $exifArray['exif:ExposureBiasValue'][1] * 100) / 100);
        if ((float) $exifArray['exif:ExposureBiasValue'] > 0) {
            $exifArray['exif:ExposureBiasValue'] = "+" .
             $exifArray['exif:ExposureBiasValue'];
        }
        $r->row2 = $r->row2 . ' 补偿:' . $exifArray['exif:ExposureBiasValue'];
        switch ($exifArray['exif:MeteringMode']) {
            case 0:
                $exifArray['exif:MeteringMode'] = "未知";
                break;
            case 1:
                $exifArray['exif:MeteringMode'] = "矩阵";
                break;
            case 2:
                $exifArray['exif:MeteringMode'] = "中央重点平均";
                break;
            case 3:
                $exifArray['exif:MeteringMode'] = "点测光";
                break;
            case 4:
                $exifArray['exif:MeteringMode'] = "多点测光";
                break;
            default:
                $exifArray['exif:MeteringMode'] = "其它";
        }
        $r->row2 = $r->row2 . ' 测光:' . $exifArray['exif:MeteringMode'];
        switch ($exifArray['exif:Flash']) {
            case 1:
                $exifArray['exif:Flash'] = "开启闪光灯";
                break;
        }
        $r->row2 = $r->row2 . '' . $exifArray['exif:Flash'];
        if ($exifArray['exif:FocalLengthIn35mmFilm']) {
            $r->row3 = '等效焦距:' . $exifArray['exif:FocalLengthIn35mmFilm'] . "mm";
        } else {
            $exifArray['exif:FocalLength'] = explode("/", 
            $exifArray['exif:FocalLength']);
            $exifArray['exif:FocalLength'] = sprintf("%4.1fmm", 
            (double) $exifArray['exif:FocalLength'][0] /
             $exifArray['exif:FocalLength'][1]);
            $r->row3 = '焦距:' . $exifArray['exif:FocalLength'];
        }
        $r->row3 = $r->row3 . ' 原始像素:' . $exifArray['exif:ExifImageWidth'] . 'x' .
         $exifArray['exif:ExifImageLength'] . 'px';
        if ($exifArray['exif:Software']) {
            $r->row3 = $r->row3 . ' 后期:' . $exifArray['exif:Software'];
        }
        return $r;
    }
    ?>
  • 相关阅读:
    redis事务详解
    redis之管道
    redis持久化
    redis之通信协议
    redis之线程IO模型
    Google、Azure、阿里云、RedHat…全球的 K8s 圈大佬聚在一起要聊啥?
    开箱即用,Knative 给您极致的容器 Serverless 体验
    2020 年 HackerEarth 调查:Go 语言成为最受欢迎的语言(内含 Go 语言图谱下载)
    Serverless 选型:深度解读 Serverless 架构及平台选择
    阿里云容器服务发布 Knative 托管服务 | 云原生生态周报 Vol. 49
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2705987.html
Copyright © 2011-2022 走看看