php画弧,PHP 绘制线段与圆弧 imageline、imagesetstyle 与 imagearc 函数

imageline() 函数用于绘制一条线段。

imagearc() 函数用于绘制椭圆弧(包括圆弧)。

imageline() 函数用于绘制一条线段。

语法:

bool imageline( resource image, int x1, int y1, int x2, int y2, int color )

用 color 颜色在图像 image 中从坐标 x1,y1 到 x2,y2(图像左上角坐标为 0,0)画一条线段。

例子:

header("Content-type: image/png");

$im = @imagecreate(300, 300)or die("创建图像资源失败");

$bg = imagecolorallocate($im, 204, 204, 204);

$red = imagecolorallocate($im, 255, 0, 0);

imageline($im,0,30,200,30,$red);

imagepng($im);

imagedestroy($im);

?>

浏览器输出图像如下:

bbfc6bcda2aae0a82b357563ecb1e006.png

参考阅读

imagesetstyle() 设定所有画线的函数(例如 imageline() 和 imagepolygon())在使用特殊颜色 IMG_COLOR_STYLED 或者用 IMG_COLOR_STYLEDBRUSHED 画一行图像时所使用的风格。如果成功则返回 TRUE ,失败则返回 FALSE 。

语法:

bool imagesetstyle( resource image, array style )

style 参数是像素组成的数组。

imageline() 函数配合 imagesetstyle() 可以画一条虚线段:

header("Content-type: image/png");

$im = @imagecreate(300, 50)or die("创建图像资源失败");

$bg = imagecolorallocate($im, 204, 204, 204);

$red = imagecolorallocate($im, 255, 0, 0);

// 画一条虚线,5 个红色像素,4 个背景像素

$style = array($red, $red, $red, $red, $red, $bg, $bg, $bg, $bg);

imagesetstyle($im, $style);

imageline($im, 0, 20, 200, 20, IMG_COLOR_STYLED);

imagepng($im);

imagedestroy($im);

?>

浏览器输出图像如下:

1ece5d8c6cf9615630b5796620962bf8.png

imagearc() 函数用于绘制椭圆弧(包括圆弧)。

语法:

bool imagearc(resource image, int cx, int cy, int w, int h, int s, int e, int color )

参数说明:

参数

说明

image

图像资源,欲绘制椭圆弧的图像

cx

椭圆中心 x 坐标

cy

椭圆中心 y 坐标

w

椭圆宽度

h

椭圆高度

s

起始点,0 表示 3 点钟方向

e

角度,360 表示完全封闭

color

图像颜色

例子:

header("Content-type: image/png");

$im = @imagecreate(200, 200)or die("创建图像资源失败");

$bg = imagecolorallocate($im, 204, 204, 204);

$red = imagecolorallocate($im, 255, 0, 0);

imagearc($im, 100, 100, 150, 150, 0, 360, $red);

imagepng($im);

imagedestroy($im);

?>

该例子绘制一个圆圈,浏览器输出如下:

bde213d6ca703e2c11028b221f4c7693.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值