📜  PHP | imagickdraw pathLineToHorizontalRelative()函数

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

PHP | imagickdraw pathLineToHorizontalRelative()函数

ImagickDraw::pathLineToHorizontalRelative()函数是PHP中的一个内置函数,用于使用相对坐标绘制从当前点到目标点的水平线路径。然后目标点成为新的当前点。

句法:

bool ImagickDraw::pathLineToHorizontalRelative( float $x )

参数:此函数接受一个包含 x 坐标的参数$x

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

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

下面给出的程序说明了PHP中的ImagickDraw::pathLineToHorizontalRelative()函数
方案一:

newImage(800, 250, 'white');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the stroke color
$draw->setStrokeColor('Green');
  
// Set the stroke width
$draw->setStrokeWidth(5);
  
// Draw line using pathLineToHorizontalRelative
$draw->pathStart();
$draw->pathMoveToRelative(0, 100);
$draw->pathLineToHorizontalRelative(1000);
$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();
  
$color = ['blue', 'red', 'green', 'yellow', 'orange', 'brown', 'pink'];
  
// Set the stroke width
$draw->setStrokeWidth(5);
  
// Draw lines
for ($x = 0; $x < 7; $x++) {
    $draw->setStrokeColor($color[$x]);
    $draw->pathStart();
    $draw->pathMoveToRelative(0, $x * 40);
    $draw->pathLineToHorizontalRelative(800);
    $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.pathlinetohorizontalrelative。 PHP