PHP | imagickdraw pushClipPath()函数
ImagickDraw::pushClipPath()函数是PHP中的一个内置函数,用于启动剪辑路径定义。剪辑路径用于创建决定应显示图像的哪一部分的剪辑区域。显示区域内的部分,而隐藏区域外的部分。
句法:
bool ImagickDraw::pushClipPath( string $clip_mask_id )
参数:此函数接受单个参数$clip_mask_id ,其中包含剪辑路径的名称。
返回值:此函数在成功时返回 TRUE。
下面的程序说明了PHP中的ImagickDraw::pushClipPath()函数:
方案一:
newImage(800, 250, 'white');
// Create a new imagickDraw object
$draw = new ImagickDraw();
// Set the stroke color
$draw->setStrokeColor('blue');
// Set the fill color
$draw->setFillColor('cyan');
// Set the stroke width
$draw->setStrokeWidth(2);
// Push the clip path
$draw->pushClipPath('testClipPath');
// Create a rectangle which is
// the area to be clipped
$draw->rectangle(0, 0, 300, 300);
// Pop the clip path
$draw->popClipPath();
// Set the clip path
$draw->setClipPath('testClipPath');
$draw->circle(150, 50, 300, 150);
// Render the draw commands
$imagick->drawImage($draw);
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
输出:
方案二:
newImage(800, 250, 'white');
// Create a new imagickDraw object
$draw = new ImagickDraw();
// Set the fill color
$draw->setFillColor('green');
// Set the font size
$draw->setFontSize(90);
// Push the clip path
$draw->pushClipPath('testClipPath');
// Create a circle which is
// the area to be clipped
$draw->circle(200, 200, 300, 300);
// Pop the clip path
$draw->popClipPath();
// Set the clip path
$draw->setClipPath('testClipPath');
// Annotate a text
$draw->annotation(115, 200, 'GeeksforGeeks');
// 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.pushclippath。 PHP