以下是一个简单的PHP实例,演示如何在画布上绘制线条。此例中使用了`GD`图形库。
```php

// 创建一个画布
$width = 500;
$height = 500;
$image = imagecreatetruecolor($width, $height);
// 分配颜色
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
// 填充背景
imagefill($image, 0, 0, $white);
// 绘制线条
// 使用imageline函数绘制线条,需要提供起始坐标和结束坐标,以及线条颜色
imageline($image, 100, 100, 400, 400, $black);
// 输出图像到浏览器
header('Content-Type: image/png');
imagepng($image);
// 释放内存
imagedestroy($image);
>
```
表格展示:
| 函数名 | 描述 |
|---|---|
| imagecreatetruecolor() | 创建一个真彩色图像,返回图像资源 |
| imagecolorallocate() | 分配颜色,返回颜色索引 |
| imagefill() | 使用指定颜色填充图像 |
| imageline() | 绘制直线 |
| header() | 发送原始的HTTP头部信息 |
| imagepng() | 输出图像到浏览器 |
| imagedestroy() | 释放图像资源,销毁图像 |







