PHP | imagickdraw pathclose()函数
ImagickDraw::pathClose()函数是PHP中的一个内置函数,用于向当前路径添加路径元素,通过绘制一条直线来关闭当前子路径。简而言之,它用于将笔划完全应用于所有边缘。
句法:
bool ImagickDraw::pathClose( void )
参数:此函数不接受任何参数。
返回值:此函数在成功时返回 TRUE。
下面的程序说明了PHP中的ImagickDraw::pathClose()函数:
方案一:
newImage(800, 250, 'black');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
// Set the stroke color
$draw->setStrokeColor('white');
// Set the stroke width
$draw->setStrokeWidth(5);
// Create a shape with four corners using
// paths with pathClose() function
$draw->pathStart();
$draw->pathMoveToAbsolute(420, 50);
$draw->pathMoveToRelative(20, 0);
$draw->pathLineToRelative(50, 90);
$draw->pathLineToVerticalRelative(30);
$draw->pathLineToHorizontalAbsolute(250);
$draw->pathClose();
$draw->pathFinish();
// 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();
// Add texts to image
$draw->annotation(100, 200, 'With pathClose()');
$draw->annotation(500, 200, 'Without pathClose()');
// Set the stroke color
$draw->setStrokeColor('green');
// Set the stroke width
$draw->setStrokeWidth(5);
// Create a shape with three coreners using
// paths (with pathClose())
$draw->pathStart();
$draw->pathMoveToAbsolute(20, 50);
$draw->pathMoveToRelative(20, 0);
$draw->pathLineToRelative(50, 90);
$draw->pathLineToVerticalRelative(0);
$draw->pathLineToHorizontalAbsolute(250);
$draw->pathClose();
$draw->pathFinish();
// Create the same shape using
// paths (without pathClose())
$draw->translate(400, 0);
$draw->pathStart();
$draw->pathMoveToAbsolute(20, 50);
$draw->pathMoveToRelative(20, 0);
$draw->pathLineToRelative(50, 90);
$draw->pathLineToVerticalRelative(0);
$draw->pathLineToHorizontalAbsolute(250);
$draw->pathFinish();
// 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.pathclose。 PHP