PHP | imagickdraw pathLineToRelative()函数
ImagickDraw::pathLineToRelative()函数是PHP中的一个内置函数,用于使用相对坐标绘制从当前点到给定坐标的直线路径。然后坐标成为新的当前点。可以使用pathMoveToRelative()函数设置初始点。
句法:
bool ImagickDraw::pathLineToRelative( float $x, float $y )
参数:该函数接受上面提到的两个参数,如下所述:
- $x:它指定起始 x 坐标。
- $y:它指定起始 y 坐标。
返回值:此函数在成功时返回 TRUE。
下面的程序说明了PHP中的ImagickDraw::pathLineToRelative()函数:
方案一:
newImage(800, 250, 'white');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
// Set the fill color
$draw->setFillColor('black');
// Create a path
$draw->pathStart();
// Draw a line
// Start coordinates of line
$draw->pathMoveToRelative(350, 50);
// End coordinates of line
$draw->pathLineToRelative(50, 150);
// End the path
$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();
// Set the fill color
$draw->setFillColor('yellow');
// Set the stroke color
$draw->setStrokeColor('black');
// Set the stroke width
$draw->setStrokeWidth(1);
// Create a path
$draw->pathStart();
// Draw a star
$draw->pathMoveToRelative(350, 20);
$draw->pathLineToRelative(40, 60);
$draw->pathLineToRelative(80, 20);
$draw->pathLineToRelative(-80, 30);
$draw->pathLineToRelative(30, 60);
$draw->pathLineToRelative(-50, -20);
$draw->pathLineToRelative(-50, 40);
$draw->pathLineToRelative(10, -70);
$draw->pathLineToRelative(-50, -10);
$draw->pathLineToRelative(50, -30);
$draw->pathLineToRelative(20, -80);
// End the path
$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.pathlinetorelative。 PHP