使用 PHP 将 .BMP 转换为 .PNG
我需要能够将不同的图像格式转换为 .PNG 格式。在其他人的帮助下,我得以实现这一目标。唯一的问题是,我还需要能够在不使用 ImageMagick 的情况下将 .BMP 文件转换为 .PNG。
这是我用于转换其他文件的代码:
<?php
$filename = "myfolder/test.jpg";
$jpg = @imagecreatefromjpeg($filename);
if ($jpg)
{
header("Content-type: image/png");
imagepng($jpg);
imagedestroy($jpg);
exit;
}
?>
如果有人知道我将如何转换它,请告诉我。欢迎并感谢所有帮助。
I needed to be able to convert different image formats to the .PNG format. With the help of some others, I was able to make that happen. The only issue is, I also need to be able to convert .BMP files to .PNG without the use of ImageMagick.
Here is the code I used for the conversion of other files:
<?php
$filename = "myfolder/test.jpg";
$jpg = @imagecreatefromjpeg($filename);
if ($jpg)
{
header("Content-type: image/png");
imagepng($jpg);
imagedestroy($jpg);
exit;
}
?>
If anyone knows how I would go about converting this, please let me know. All help is welcome and appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Github 上有一个新的开源项目,允许在 PHP 中读取和保存 BMP 文件(和其他文件格式)。
该项目名为 PHP Image Magician。
There is a new opensource project on Github that allows reading and saving of BMP files (and other file formats) in PHP.
The project is called PHP Image Magician.
GD 中没有内置标准 BMP 的功能。但是,如果您查看
imagecreatefromwbmp
< 的文档页面/a> 其他人发布了一些解决方案,您可以尝试。手动读取图像数据并从中构建 GD 图像资源,然后将其保存为任何格式。There is not built in functionlaity for standard BMP's in GD. However, if you look at the documentation page for
imagecreatefromwbmp
there are some solutions posted by others you can try. The deal with reading the image data manually and constructing a GD image resource from it which could then be saved as whatever format.