📜  PHP | imagickdraw pathLineToVerticalRelative()函数

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

PHP | imagickdraw pathLineToVerticalRelative()函数

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

句法:

bool ImagickDraw::pathLineToVerticalRelative( float $y )

参数:此函数接受单个参数$y ,它保存 y 坐标。

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

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

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

方案一:

newImage(800, 250, 'white');
   
// Create a new ImagickDraw object
$draw = new ImagickDraw();
   
// Set the stroke color
$draw->setStrokeColor('blue');
   
// Set the stroke width
$draw->setStrokeWidth(5);
   
// Draw line using pathLineToVerticalRelative
$draw->pathStart();
$draw->pathMoveToRelative(400, 0);
$draw->pathLineToVerticalRelative(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 < 20; $x++) {
    $draw->setStrokeColor($color[$x % 7]);
    $draw->pathStart();
    $draw->pathMoveToRelative($x * 40, 0);
    $draw->pathLineToVerticalRelative(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.pathlinetoverticalrelative。 PHP