牛牛在线工具

imagefill()

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

imagefill()

在图像中填充颜色

函数名:imagefill() 函数描述:imagefill() 函数用于在图像中填充颜色。 适用版本:该函数适用于 PHP 4、PHP 5、PHP 7。 语法:bool imagefill(resource $image, int $x, int $y, int $color) 参数: $image:必需,图像资源标识符,通过 imagecreatetruecolor() 或 imagecreatefrom*() 函数创建。 $x:必需,填充的起始点 x 坐标。 $y:必需,填充的起始点 y 坐标。 $color:必需,填充的颜色,可以使用 imagecolorallocate() 函数来创建。 返回值:成功时返回 true,失败时返回 false。 示例: // 创建一个 200x200 的空白图像 $image = imagecreatetruecolor(200, 200); // 创建一个红色的填充颜色 $red = imagecolorallocate($image, 255, 0, 0); // 填充图像以红色 imagefill($image, 0, 0, $red); // 输出图像到浏览器 header('Content-Type: image/png'); imagepng($image); // 销毁图像资源 imagedestroy($image); 以上示例创建了一个 200x200 的空白图像,然后使用 imagecolorallocate() 函数创建了一个红色的填充颜色。接下来,使用 imagefill() 函数将整个图像填充为红色。最后,通过 header() 函数设置图像的 MIME 类型为 image/png,并使用 imagepng() 函数将图像输出到浏览器。最后,使用 imagedestroy() 函数销毁图像资源,释放内存。