php imagedashedline,PHP imagedashedline()用法及代码示例

imagedashedline()函数是PHP中的内置函数,用于绘制虚线。成功时此函数返回TRUE,否则返回FALSE。

用法:

bool imagedashedline( $image , $x1 , $y1 , $x2 , $y2 , $color )

参数:该函数接受上述和以下所述的六个参数:

$image:imagecreatetruecolor()函数用于创建给定尺寸的空白图像。

$x1:此参数用于保留左上角的x坐标。

$y1:此参数用于保留左上y坐标。 (0,0)是图像的左上角。

$x2:此参数用于保存右下角的x坐标。

$y2:此参数用于保留右下角的y坐标。

$color:此变量包含填充的颜色标识符。使用imagecolorallocate()函数创建的颜色标识符。

返回值:如果成功,则此函数返回TRUE;如果失败,则返回FALSE。

以下示例程序旨在说明PHP中的imagedashedline()函数。

程序1:

// Create the size of image or blank image

$image = imagecreatetruecolor(400, 300);

// Set the background color of image

$background_color = imagecolorallocate($image,  0, 153, 0);

// Fill background with above selected color

imagefill($image, 0, 0, $background_color);

// Set the color of dotted line in image

$color = imagecolorallocate($image,  255, 255, 255);

// Draw a dashed line

imagedashedline($image, 0, 0, 100, 150, $color);

// Output the image

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

imagepng($image);

?>

输出:

c8cb5f7ceb44f2d09c5900d0ac89b779.png

程序2:

// Create the size of image or blank image

$image = imagecreatetruecolor(400, 300);

// Set the background color of image

$background_color = imagecolorallocate($image,  0, 153, 0);

// Fill background with above selected color

imagefill($image, 0, 0, $background_color);

// Set the color of dotted line in image

$white = imagecolorallocate($image, 255, 255, 255);

// $value is an array variable stored color

// code of dotted image

$values = Array(

$white,

$white,

$white,

$white,

IMG_COLOR_TRANSPARENT,

IMG_COLOR_TRANSPARENT,

IMG_COLOR_TRANSPARENT,

IMG_COLOR_TRANSPARENT

);

imagesetstyle($image, $values);

// Draw the dashed line

imageline($image, 50, 150, 300, 150, IMG_COLOR_STYLED);

// Save the image

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

imagepng($image);

?>

输出:

4e90b070f7320e927f85005aeedb687a.png

相关文章:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值