Swoole\Image::cut PHP Method

cut() static public method

裁切图片
static public cut ( $pic, $dst_pic, $width, $height = null, $qulitity = 100 ) : boolean
$pic string 源图像
$dst_pic string 目标图像
$width int 宽度
$height int 高度
$qulitity int 质量
return boolean
    static function cut($pic, $dst_pic, $width, $height = null, $qulitity = 100)
    {
        $im = imagecreatefromjpeg($pic);
        if (imagesx($im) > $width) {
            $old_w = imagesx($im);
            $old_h = imagesy($im);
            if ($height == null) {
                $w_h = $old_w / $old_h;
                $height = $width * $w_h;
            }
            $newim = imagecreatetruecolor($width, $height);
            imagecopyresampled($newim, $im, 0, 0, 0, 0, $width, $height, $old_w, $old_h);
            imagejpeg($newim, $dst_pic, $qulitity);
            imagedestroy($im);
            return true;
        } elseif ($pic != $dst_pic) {
            return copy($pic, $dst_pic);
        }
        return false;
    }