English | 简体中文 | 繁體中文
查询

imagewbmp()函数—用法及示例

「 将图像以 WBMP 格式输出或保存到文件中 」


函数名:imagewbmp()

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

函数说明:imagewbmp() 函数用于将图像以 WBMP 格式输出或保存到文件中。

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

参数:

  • $image:必需,图像资源,由 imagecreatefromwbmp() 或 imagecreatefromstring() 创建。
  • $filename:可选,保存的文件名。如果不提供此参数,则直接输出图像到浏览器。
  • $foreground:可选,前景色的颜色索引。默认为黑色。

返回值:

  • 成功时返回 true,失败时返回 false。

示例一:将图像输出到浏览器

$image = imagecreatefromwbmp('image.wbmp');
header('Content-Type: image/vnd.wap.wbmp');
imagewbmp($image);
imagedestroy($image);

示例二:将图像保存到文件

$image = imagecreatefromwbmp('image.wbmp');
imagewbmp($image, 'output.wbmp');
imagedestroy($image);

注意事项:

  • imagewbmp() 函数需要 GD 库的支持。在编译 PHP 时需要加入 "--with-gd" 选项。
  • 如果要输出 WBMP 图像到浏览器,请确保在调用 imagewbmp() 之前设置正确的 Content-Type 头信息。
  • 如果要保存图像到文件,请确保 PHP 进程对保存文件的目录有写权限。
补充纠错
上一个函数: imagetypes()函数
下一个函数: imagewebp()函数
热门PHP函数
分享链接