zoukankan      html  css  js  c++  java
  • ImageMagick 图片处理 函数说明和使用举例

    ImageMagick 函数说明和使用举例,作者:打打 QQ:1069576404

    首先,加载php_imagick.dll扩展模块,也就是在网上找到php_imagick.dll文件,把它放在php.ini同级的目录中,然后,在php.ini里加上extension=php_imagick.dll,重启服务器就可以了。

    函数说明:

    $images = new Imagick("ALIM2382.JPG");//新建 Imagick 类
    $images->getImageHeight();//获得图片高
    $images->getImageWidth();//获得图片宽
    $images->thumbnailImage(100,100);////改变图片的大小
    $images->writeImages("ALIM2382.JPG",true);//写一个图像或图像序列
    $images->writeImage("ALIM2382.JPG");//写一个图像
    $images->destroy();//销毁图片
    $images->borderImage(new ImagickPixel("red"), 3, 3);//设置图片边框红色,边框为3
    $images->modulateImage(50, 0, 0); //控制亮度、饱和度、色调
    $images->compositeImage($im, imagick::COMPOSITE_OVER, 10, 20);//将两个图像符合到一起。
    $images->setImageFormat('jpeg');//设置图片格式
    $images->getImageResolution()// 返回图像分辨率,X和Y轴信息
    $images->getImageUnits()//     返回图像分辨率单位
    $images->resampleImage()// 以期望的分辨率重新采样
    $images->setImageResolution()//       设置分辨率
    $images->setImageUnits()//   设置分辨率单位
    echo $images;//显示
    其他请参考 http://cn.php.net/imagick 网站

    实例演示:

    $img='ALIM2382.JPG';
    //生成图片
    $images=doimage_middle($img);
    //显示图片
    echo $images;
    //销毁
    $images->destroy();

    //生成图片效果请参考‘我的相册’。


    //返回文件的扩展名
    function extension($filename)
    {
        $img_ext="";
        $path_parts = pathinfo($filename);
        $img_ext=$path_parts["extension"];
        return $img_ext;
    }
    //生成图片
    function doimage_middle($imgname)
    {
    //获得文件扩展名
    $img_ext=extension($imgname); 
        //新建 Imagick 类
    $images = new Imagick($imgname);
        $Height = $images->getImageHeight();
    $Width = $images->getImageWidth();
    //获得宽高的比率
        $ratio = Resize($Height,$Width);
        $new_width = $Width*$ratio;
        $new_height = $Height*$ratio;
    //改变图片的大小为:
    $images->thumbnailImage($new_width,$new_height);
    //写一个图像或图像序列
    $images->writeImage($imgname.'_middle.'.$img_ext);
    return $images;
    }

    //获得 图片宽高的比率
    function Resize( $height,$width, $maxwidth=400, $maxheight=400){
    $RESIZEWIDTH=$RESIZEHEIGHT=false;
    if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
       if($maxwidth && $width > $maxwidth){
       $widthratio = $maxwidth/$width;
       $RESIZEWIDTH=true;
       }
       if($maxheight && $height > $maxheight){
       $heightratio = $maxheight/$height;
       $RESIZEHEIGHT=true;
       }
       if($RESIZEWIDTH && $RESIZEHEIGHT){
        if($widthratio < $heightratio){
         $ratio = $widthratio;
        }else{
         $ratio = $heightratio;
        }
       }elseif($RESIZEWIDTH){
        $ratio = $widthratio;
       }elseif($RESIZEHEIGHT){
        $ratio = $heightratio;
       }

    }else{
       $ratio=1;
    }
    return $ratio;
    }

  • 相关阅读:
    POJ 3268 Silver Cow Party (Dijkstra)
    怒学三算法 POJ 2387 Til the Cows Come Home (Bellman_Ford || Dijkstra || SPFA)
    CF Amr and Music (贪心)
    CF Amr and Pins (数学)
    POJ 3253 Fence Repair (贪心)
    POJ 3069 Saruman's Army(贪心)
    POJ 3617 Best Cow Line (贪心)
    CF Anya and Ghosts (贪心)
    CF Fox And Names (拓扑排序)
    mysql8.0的新特性
  • 原文地址:https://www.cnblogs.com/mfryf/p/2360318.html
Copyright © 2011-2022 走看看