imagecreatefrombmp
从文件或URL创建新图像
该函数适用于 PHP 5 及以上版本。
imagecreatefrombmp 函数用于从 BMP 文件创建一个图像资源。该图像资源可以用于后续的图像处理和输出。
resource imagecreatefrombmp ( string $filename )
如果成功,返回一个图像资源(资源类型)。如果失败,返回 false。
以下是一个使用 imagecreatefrombmp 函数的示例:
<?php $filename = "example.bmp"; // 设置要加载的 BMP 文件路径 $image = imagecreatefrombmp($filename); // 加载 BMP 文件为图像资源 if ($image !== false) { echo "图像加载成功!"; // 可以在这里进行图像处理,例如输出图像或保存 header('Content-Type: image/png'); imagepng($image); // 输出图像为 PNG 格式 imagedestroy($image); // 释放图像资源 } else { echo "加载图像失败!"; } ?>
在上面的示例代码中: