📜  PHP | imagickdraw pathfinish()函数

📅  最后修改于: 2022-05-13 01:56:30.586000             🧑  作者: Mango

PHP | imagickdraw pathfinish()函数

ImagickDraw::pathFinish()函数是PHP中的一个内置函数,用于终止当前路径。当要在图像中绘制多条路径时,这是必需的。

句法:

bool ImagickDraw::pathFinish( void )

参数:此函数不接受任何参数。

返回值:此函数在成功时返回 TRUE。

异常:此函数在出错时抛出 ImagickException。

下面的程序说明了PHP中的ImagickDraw::pathFinish()函数

方案一:

newImage(800, 250, '#1a65f0');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
$draw->setFillColor('#2fceeb');
  
// Set the stroke color
$draw->setStrokeColor('black');
  
// Set the stroke width
$draw->setStrokeWidth(15);
  
// Create a path
$draw->pathStart();
$draw->pathMoveToAbsolute(50, 50);
$draw->pathLineToAbsolute(100, 50);
$draw->pathLineToRelative(0, 50);
$draw->pathLineToHorizontalRelative(-50);
$draw->pathFinish();
  
// Create another path
$draw->pathStart();
$draw->pathMoveToAbsolute(50, 50);
$draw->pathMoveToRelative(300, 0);
$draw->pathLineToRelative(50, 0);
$draw->pathLineToVerticalRelative(50);
$draw->pathLineToHorizontalAbsolute(350);
$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, '#1a65f0');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
$draw->setFillColor('red');
  
// Set the stroke color
$draw->setStrokeColor('black');
  
// Set the stroke width
$draw->setStrokeWidth(1);
  
// Create a path
$draw->pathStart();
$draw->pathMoveToAbsolute(50, 50);
$draw->pathLineToAbsolute(100, 150);
$draw->pathLineToRelative(0, 50);
$draw->pathLineToHorizontalRelative(-50);
$draw->pathFinish();
  
$x = 0;
for ($x; $x < 10; $x++) {
  
    // Create another path
    $draw->pathStart();
    $draw->pathMoveToAbsolute(50, 150);
    $draw->pathMoveToRelative($x * 100, 0);
    $draw->pathLineToRelative(50, 0);
    $draw->pathLineToVerticalRelative(50);
    $draw->pathLineToHorizontalAbsolute(350);
    $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();
?>

输出:

参考: https://www. PHP.net/manual/en/imagickdraw.pathfinish。 PHP