Imagick::cropImage

(PECL imagick 2, PECL imagick 3)

Imagick::cropImage截圖圖片的一塊區(qū)域

說明

Imagick::cropImage(
    int $width,
    int $height,
    int $x,
    int $y
): bool

截圖圖片的一塊區(qū)域

參數(shù)

width

截圖的寬度

height

截圖的高度

x

裁剪區(qū)域左上角的 X 軸坐標(biāo)(以原圖的左上角為原點(diǎn))

y

裁剪區(qū)域左上角的 X 軸坐標(biāo)(以原圖的左上角為原點(diǎn))

返回值

成功時(shí)返回 true

錯(cuò)誤/異常

錯(cuò)誤時(shí)拋出 ImagickException。

范例

示例 #1 Imagick::cropImage()

<?php
function cropImage($imagePath$startX$startY$width$height) {
    
$imagick = new \Imagick(realpath($imagePath));
    
$imagick->cropImage($width$height$startX$startY);
    
header("Content-Type: image/jpg");
    echo 
$imagick->getImageBlob();
}

?>