moveto php,PHP ImagickDraw pathMoveToAbsolute()用法及代码示例

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

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();

?>

输出:

79676682645d1b56eb963bf9b9a092f0.png

程序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();

?>

输出:

a143252bd47b2937b914b6f9d37e309e.png

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值