在线工具 | 热点资讯 | 网站目录 | 简繁转换 | 英语单词
查询

imagexbm()函数—用法及示例

「 将 XBM 图像输出到浏览器或文件 」


函数名:imagexbm()

适用版本:PHP 4, PHP 5, PHP 7

函数描述:imagexbm() 函数用于将 XBM 图像输出到浏览器或文件。

语法:bool imagexbm ( resource $image , string $filename [, int $foreground ] )

参数:

  • $image:必需,表示图像资源,使用 imagecreatefromxbm() 创建。
  • $filename:必需,表示输出的文件名或路径。如果未设置或为 NULL,则直接输出到浏览器。
  • $foreground:可选,表示前景颜色的索引值(0-255)。默认为黑色。

返回值:成功时返回 true,失败时返回 false。

示例:

  1. 输出到浏览器:
$width = 100;
$height = 100;
$image = imagecreate($width, $height);
$foreground = imagecolorallocate($image, 0, 0, 0); // 黑色
imagexbm($image, NULL, $foreground);
imagedestroy($image);
  1. 输出到文件:
$width = 100;
$height = 100;
$image = imagecreate($width, $height);
$foreground = imagecolorallocate($image, 0, 0, 0); // 黑色
imagexbm($image, 'output.xbm', $foreground);
imagedestroy($image);

以上示例中,我们创建了一个宽高为 100 像素的黑色图像,并通过 imagexbm() 函数将其输出到浏览器或文件中。如果指定了文件名,则会将图像保存为 XBM 文件。否则,图像将直接输出到浏览器。

补充纠错
上一个函数: imagewebp()函数
下一个函数: image_type_to_extension()函数
热门PHP函数
分享链接