imageline
画一条线
PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8
imageline() 函数用于在图像中绘制一条线段。线段的起点和终点可以通过指定坐标来定义。该函数适用于使用 GD 库的图像处理任务。
imageline(resource $image, int $x1, int $y1, int $x2, int $y2, int $color): bool
返回布尔值,成功时返回 true,失败时返回 false。
$image = imagecreatetruecolor(200, 200); $color = imagecolorallocate($image, 255, 0, 0); // 红色 <p>// 在图像上绘制一条从 (10, 10) 到 (190, 190) 的红色线段<br> imageline($image, 10, 10, 190, 190, $color);</p> <p>// 输出图像<br> header('Content-Type: image/png');<br> imagepng($image);<br> imagedestroy($image);<br>
此示例代码首先创建了一个 200x200 像素的图像资源。然后,使用 imagecolorallocate() 创建了一个红色的颜色资源。接着,使用 imageline() 绘制了从坐标 (10, 10) 到坐标 (190, 190) 的红色线段。最后,使用 imagepng() 输出图像,并且通过 imagedestroy() 销毁图像资源以释放内存。