imagexbm
将XBM图像输出到浏览器或文件
imagexbm
此函数适用于 PHP 版本 4.3.0 及以上版本。
imagexbm() 函数用于将图像输出为 XBM 格式。XBM 是一种以 ASCII 码表示的位图图像格式,通常用于生成图像文件,特别是图标。
imagexbm(resource $image, string $filename = NULL, int $foreground = -1): bool
成功时返回 TRUE,失败时返回 FALSE。
以下是使用 imagexbm() 函数将图像保存为 XBM 格式的示例代码:
<?php // 创建一个空白图像资源 $image = imagecreate(100, 100); <p>// 分配颜色<br> $background_color = imagecolorallocate($image, 255, 255, 255); // 白色背景<br> $foreground_color = imagecolorallocate($image, 0, 0, 0); // 黑色前景</p> <p>// 绘制一个简单的矩形<br> imagefilledrectangle($image, 10, 10, 90, 90, $foreground_color);</p> <p>// 将图像保存为 XBM 格式<br> imagexbm($image, "image.xbm");</p> <p>// 释放图像资源<br> imagedestroy($image);<br> ?><br>
这段代码首先创建了一个 100x100 的空白图像,并分配了白色和黑色的背景和前景色。接着,绘制了一个黑色的矩形,并通过 imagexbm() 函数将图像保存为一个名为 "image.xbm" 的文件。最后,释放了图像资源。