PHP | imagickdraw setClipPath()函数
ImagickDraw::setClipPath()函数是PHP中的一个内置函数,用于将命名的剪切路径与图像相关联。只要剪切路径仍然有效,只会修改剪切路径所绘制的区域。
句法:
bool ImagickDraw::setClipPath( string $clip_mask )
参数:此函数接受单个参数$clip_mask保存剪辑蒙版。
返回值:此函数在成功时返回 TRUE。
异常:此函数在出错时抛出 ImagickException。
下面给出的程序说明了PHP中的ImagickDraw::setClipPath()函数:
方案一:
setClipPath('nameOfClipPath');
// Get clip path
echo $draw->getClipPath();
?>
输出:
nameOfClipPath
方案二:
newImage(800, 250, 'green');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
// Setup a clipPath
$draw->pushClipPath('myClipPath');
$draw->rectangle(100, 40, 200, 200);
$draw->popClipPath();
$draw->setClipPath('myClipPath');
// Extra commands which are going to
// be ignore as they are outside the
// area of the clipPath
$draw->rectangle(10, 100, 400, 400);
$draw->line(100, 100, 400, 400);
// Render the draw commands
$imagick->drawImage($draw);
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
输出:
参考: https://www. PHP.net/manual/en/imagickdraw.setclippath。 PHP