ImagickDraw::pathMoveToAbsolute()函数是PHP中的内置函数,用于使用绝对坐标在给定坐标处启动新的sub-path。然后,当前点成为指定的坐标。此功能用于在开始绘制任何东西之前设置初始坐标。
用法:
bool ImagickDraw::pathMoveToAbsolute( float $x, float $y )
参数:该函数接受上述和以下描述的两个参数:
$x:它指定x坐标。
$y:它指定y坐标。
返回值:成功时此函数返回TRUE。
异常:该函数在错误时引发ImagickException。
下面给出的程序说明了PHP中的ImagickDraw::pathMoveToAbsolute()函数:程序1:
// Create a new imagick object
$imagick = new Imagick();
// Create a image on imagick object
$imagick->newImage(800, 250, 'white');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
// Set the stroke width
$draw->setStrokeWidth(30);
$draw->pathStart();
// Setting the stating point to (400, 40)
$draw->pathMoveToAbsolute(400, 40);
// Setting the end point to (500, 40)
$draw->pathLineToHorizontalAbsolute(500);
$draw->pathFinish();
// Render the draw commands
$imagick->drawImage($draw);
// Show the output
$imagick->setImageFormat('png');
header("Content-Type:image/png");
echo $imagick->getImageBlob();
?>
输出:

程序2:
// Create a new imagick object
$imagick = new Imagick();
// Create a image on imagick object
$imagick->newImage(800, 250, 'white');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
$color = ['blue', 'red', 'green'];
// Set the stroke width
$draw->setStrokeWidth(5);
// Draw lines
for ($x = 0; $x < 20; $x++) {
$draw->setStrokeColor($color[$x % 3]);
$draw->pathStart();
// Moving to next vertical line
$draw->pathMoveToAbsolute($x * 40, 0);
$draw->pathLineToVerticalRelative(800);
$draw->pathFinish();
}
for ($x = 0; $x < 20; $x++) {
$draw->setStrokeColor($color[$x % 3]);
$draw->pathStart();
// Moving to next horizontal line
$draw->pathMoveToAbsolute(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();
?>
输出:

本文介绍了PHP中ImagickDraw::pathMoveToAbsolute()函数的使用方法,该函数通过绝对坐标来设置子路径的起始点。文章通过两个实例展示了如何使用此函数绘制水平和垂直线条。
476

被折叠的 条评论
为什么被折叠?



