PHP 中的 imagefilledrectangle() 函数
phpserver side programmingprogramming更新于 2025/7/6 16:22:17
imagefilledrectangle() 函数用于绘制一个填充矩形。
语法
imagefilledrectangle( $img, $x1, $y1, $x2, $y2, $color )
参数
image
使用 imagecreatetruecolor() 创建一张空白图像。x1
点 1 的 x 坐标。y1
点 1 的 y 坐标。x2
点 1 的 x 坐标2.y2
点 2 的 y 坐标。color
填充颜色。
返回
imagefilledrectangle() 函数成功时返回 TRUE,失败时返回 FALSE。
示例
以下是示例:
<?php
// 创建图像
$img = imagecreatetruecolor(500, 300);
$color = imagecolorallocate($img, 0, 128, 128);
imagefilledrectangle($img, 30, 30, 470, 270, $color);
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
?>
输出
输出结果如下:


