我正在尝试从 BMP 图像创建 GD 图像资源,但是我没有运气。
所讨论的 BMP 图像是使用 Photoshop 创建并保存的。我也尝试了在网上找到的几个 BMP,它们给出了相同的结果。
getimagesize() 告诉我 BMP 图像的图像类型为 IMAGETYPE_BMP (6),MIME 类型为“image/x-ms-bmp”。
我尝试通过 imagecreatefromwbmp() 和 imagecreatefromxbm() 运行图像,但都无法识别它。我还尝试通过 imagecreatefromstring() 运行它,但错误提示“数据不是可识别的格式”。
我在 Windows 机器上运行 XAMPP,运行 PHP 5.3.1 和 GD 2.0.34,并启用 WBMP 和 XBM 支持。我还在运行 PHP 5.2.6 和 GD 2.0.34 且启用了 WBMP 和 XBM 支持的 Linux 服务器上尝试过此操作,结果相同。
有什么想法可以如何从此 BMP 创建 GD 图像资源吗?实际上可能吗?
I'm trying to create a GD image resource from a BMP image, however I'm having no luck.
The BMP image in question was created and saved with Photoshop. I've tried a couple of BMPs I found on the web too, and they gave the same results.
getimagesize() tells me the BMP image has an image type of IMAGETYPE_BMP (6) and a MIME type of 'image/x-ms-bmp'.
I've tried running the image through imagecreatefromwbmp() and imagecreatefromxbm(), but neither recognise it. I've also tried running it through imagecreatefromstring(), but that errored saying 'Data is not in a recognized format'.
I'm running XAMPP on a Windows machine with PHP 5.3.1 and GD 2.0.34 with WBMP and XBM support enabled. I've also tried this on a Linux server running PHP 5.2.6 and GD 2.0.34 with WBMP and XBM support enabled, same result.
Any ideas how I can create a GD image resource from this BMP? Is it actually possible?
发布评论
评论(6)
据我所知,它不支持BMP图像。
imagecreatefromwbmp()
方法用于处理无线位图 (WBMP) 文件,而不是普通的 BMP 文件。imagecreatefromxbm()
用于处理 XBM 格式(同样,与 BMP 不同)。我会通过重新打开 Photoshop 并重新保存为 PNG 或 JPG 来解决此问题。假设您已安装/编译了具有适当支持的 PHP,您将能够很好地使用其中一种或两种图像格式。
As far as I know, it doesn't support BMP images. The
imagecreatefromwbmp()
method is for dealing with wireless bitmaps (WBMP) files, not the normal BMP you have there. Theimagecreatefromxbm()
is for dealing with the XBM format (again, different from BMP).I would work around this by re-opening Photoshop and re-saving as PNG or JPG. Assuming you have PHP installed/compiled with the appropriate support, you'll be able to work with one or both of those image formats fine.
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. It's pretty easy to use.
The project is called PHP Image Magician.
您正在寻找的解决方案在这里:
http://tr.php.net/imagecreate
在下面滚动到注释以查找名为“的函数” ImageCreateFromBMP”。
它将帮助您从 bmp 图像创建图像。
创建图像后,您可以使用 imagejpeg() 函数将图像保存为 jpeg 格式。
The solution you are looking for is here:
http://tr.php.net/imagecreate
Scroll below to the comments to find the function named "ImageCreateFromBMP".
It will help you create images from the bmp images.
Once you create the image you can use the imagejpeg() function to save the image in jpeg format.
PHP 7.2 在 GD 库中引入了对 BMP 的支持: imagebmp, imagecreatefrombmp。
PHP 7.2 introduced support for BMP in GD library: imagebmp, imagecreatefrombmp.
我好像记得很久以前就知道GD不支持BMP格式。
这是我刚刚找到的链接。
虽然关于WBMP文件有些混乱,但那是很久以前的事了。
此时间线< Delicious.com 的 /a> 表明这可能是 2005 年。
I seem to recall learning a long time ago that GD doesn't support BMP format.
Here's a link I just found.
Although there was some confusion about WBMP files, it was a long time ago.
This timeline from Delicious.com indicates it was probably 2005.
使用功能:
来源
http://php.net/manual/ru/function.imagecreatefromwbmp.php
use function :
source
http://php.net/manual/ru/function.imagecreatefromwbmp.php