美文网首页
对图片进行缩放

对图片进行缩放

作者: 孤岛渔夫 | 来源:发表于2016-12-04 01:54 被阅读0次
    <?php 
    // 打开图片资源
    $src = imagecreatefromjpeg('./Meinv010.jpg');

    // 创建新的画布
    $dst = imagecreatetruecolor(300,300); 

    $img_info = autoOpen('./Meinv010.jpg');

    // 缩放图片
    // imagecopyresampled(dst,src, dst_x, dst_y, src_x, src_y,  dst_w,dst_h,  src_w,src_h)
    imagecopyresampled($dst, $src, 0,0,  0,0, 300,300, $img_info['width'], $img_info['height']);

    // 保存资源
    imagejpeg($dst,'./zoom.jpg');
    imagedestroy($dst);
    imagedestroy($src);











    function autoOpen($img_path){
        $arr = getimagesize($img_path);
        $img_info['width'] = $arr[0];
        $img_info['height'] = $arr[1];
        $img_info['mime'] = $arr['mime'];

        // imagecreatefromjpeg()
        // imagecreatefrompng()
        // imagecreatefromgif()
        
        // 获取格式类型
        $type = ltrim(strchr($arr['mime'],'/'),'/');

        $func = 'imagecreatefrom'.$type;
        $img_info['resource'] = $func($img_path);

        return $img_info;
    }
 ?>

相关文章

网友评论

      本文标题:对图片进行缩放

      本文链接:https://www.haomeiwen.com/subject/befhmttx.html