当前位置: 首页> 函数类别大全> imagefilledrectangle

imagefilledrectangle

绘制一个填充的矩形
名称:imagefilledrectangle
分类:图像处理GD
所属语言:php
一句话介绍:绘制一个填充的矩形

imagefilledrectangle 函数

适用 PHP 版本:PHP 4.3.0 及以上版本

函数说明

imagefilledrectangle 函数用于在图像上绘制一个填充的矩形。

函数语法

imagefilledrectangle(resource $image, int $x1, int $y1, int $x2, int $y2, int $color): bool

参数

  • image (resource):图像资源,通常是通过创建图像函数(如 imagecreate())创建的图像。
  • x1 (int):矩形的左上角 x 坐标。
  • y1 (int):矩形的左上角 y 坐标。
  • x2 (int):矩形的右下角 x 坐标。
  • y2 (int):矩形的右下角 y 坐标。
  • color (int):矩形填充颜色,可以通过 imagecolorallocate() 函数获取。

返回值

该函数成功时返回 true,失败时返回 false

示例

以下是一个使用 imagefilledrectangle 函数的示例:

示例代码:

  <?php
  // 创建一个空白图像
  $image = imagecreate(200, 200);
<p>// 分配颜色<br>
$bg_color = imagecolorallocate($image, 255, 255, 255); // 背景颜色为白色<br>
$rect_color = imagecolorallocate($image, 255, 0, 0);   // 矩形颜色为红色</p>
<p>// 在图像上绘制填充矩形<br>
imagefilledrectangle($image, 50, 50, 150, 150, $rect_color);</p>
<p>// 输出图像<br>
header('Content-Type: image/png');<br>
imagepng($image);</p>
<p>// 销毁图像资源<br>
imagedestroy($image);<br>
?><br>

示例代码的说明:

这段代码首先创建一个 200x200 像素的空白图像,并为其分配白色背景和红色矩形的填充颜色。接着,通过调用 imagefilledrectangle 函数,在图像上绘制了一个位于坐标 (50, 50) 到 (150, 150) 之间的红色填充矩形。最后,图像通过 imagepng 函数输出为 PNG 格式,并销毁图像资源。

同类函数
热门文章