PHP | Gmagick Chopimage()函数
Gmagick::chopimage()函数是PHP中的一个内置函数,用于删除图像的区域并对其进行修剪。此函数接受图像的尺寸并从要修剪图像的区域和尺寸中切出。
句法:
Gmagick Gmagick::chopimage( $width, $height, $x, $y )
参数:该函数接受上面提到的四个参数,如下所述:
- $width:此参数保存切碎区域的宽度。
- $height:此参数保存切碎区域的高度。
- $x:此参数保存切碎区域的 x 原点。
- $y:此参数保存切碎区域的 y 原点。
返回值:此函数返回切碎的 Gmagick 对象。
错误/异常:此函数在错误时抛出 GmagickException。
下面的程序说明了PHP中的Gmagick::chopimage()函数:
方案一:
原图:
php
chopimage(45, 20, 45, 300);
header('Content-type: image/png');
// Output the image
echo $gmagick;
?>
php
setStrokeOpacity(1);
$draw->setStrokeColor('Red');
$draw->setFillColor('Green');
// Set the width and height of image
$draw->setStrokeWidth(7);
$draw->setFontSize(72);
// Function to draw circle
$draw->circle(250, 250, 100, 150);
$gmagick = new Gmagick();
$gmagick->newImage(500, 500, 'White');
$gmagick->setImageFormat("png");
$gmagick->drawImage($draw);
// Use chopimage() function
$gmagick->chopimage(45, 20, 75, 200);
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>
输出:
方案二:
PHP
setStrokeOpacity(1);
$draw->setStrokeColor('Red');
$draw->setFillColor('Green');
// Set the width and height of image
$draw->setStrokeWidth(7);
$draw->setFontSize(72);
// Function to draw circle
$draw->circle(250, 250, 100, 150);
$gmagick = new Gmagick();
$gmagick->newImage(500, 500, 'White');
$gmagick->setImageFormat("png");
$gmagick->drawImage($draw);
// Use chopimage() function
$gmagick->chopimage(45, 20, 75, 200);
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>
输出:
参考: http: PHP。 PHP