牛牛在线工具

imagefilledrectangle()

收录 8868 个 PHP 函数,含用途说明与用法示例。

imagefilledrectangle()

在图像上绘制一个填充的矩形

函数名称:imagefilledrectangle() 函数描述:该函数用于在图像上绘制一个填充的矩形。 用法: imagefilledrectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color ) : bool 参数: $image:图像资源,通过imagecreate()或imagecreatefromXXX()函数创建。 $x1:矩形左上角的 x 坐标。 $y1:矩形左上角的 y 坐标。 $x2:矩形右下角的 x 坐标。 $y2:矩形右下角的 y 坐标。 $color:填充颜色,可以是一个整数表示的颜色值,或使用imagecolorallocate()函数创建的颜色资源。 返回值: 如果成功绘制矩形,则返回 true。如果失败,则返回 false。 示例: // 创建一个宽度为 400,高度为 200 的空白图像 $image = imagecreate(400, 200); // 分配填充颜色 $fillColor = imagecolorallocate($image, 255, 0, 0); // 红色 // 绘制一个填充的矩形 imagefilledrectangle($image, 50, 50, 150, 150, $fillColor); // 输出图像 header('Content-type: image/png'); imagepng($image); // 释放内存 imagedestroy($image); 上述示例中,我们首先创建了一个宽度为400,高度为200的空白图像。然后使用imagecolorallocate()函数分配了一个红色作为填充颜色。最后,使用imagefilledrectangle()函数在图像上绘制了一个左上角坐标为(50, 50),右下角坐标为(150, 150)的填充矩形。最后,通过设置header()函数输出图像,并通过imagedestroy()函数释放内存。