Reputation: 1397
Just wondering if anybody knew how to convert a bmp byte array into an actual image?
image extract :
424d 4284 0300 0000 0000 4200 0000 2800
0000 4001 0000 f000 0000 0100 1800 0300
This doesnt work with bmp (where data is the input string representing the image)
$im = imagecreatefromstring($data);
if ($im !== false) {
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
}
else {
echo 'An error occurred.';
}
Thanks!
Upvotes: 1
Views: 1923
Reputation: 8226
It seems that BMP is not supported by imagecreatefromstring() or PHP's GD for that matter [1]
It seems to support WBMP, which is not BMP. [2]
And besides, imagecreatefromstring() expects to receive the whole file, not just "an extract" of any chosen pixels you might have. If it would accept raw pixel data (forgetting such issues as color format, bit count etc.), you would still need to specify at least the pixels-per line to imagecreatefromstring() for GD to make up anything of your "raw data".
Because of the nature of BMP where the data is uncompressed pixel data, if you really REALLY need to, I guess you could imagecreate() an empty image and use imagesetpixel() in a for (y) { for (x) { ... } } loop to set the pixel data from an extract from the original BMP file. Not knowing what you're trying to do, I'd still bet there'd be easier ways to do it.
[1] http://php.net/manual/en/function.imagecreatefromstring.php / "imagecreatefromstring() returns an image identifier representing the image obtained from the given image. These types will be automatically detected if your build of PHP supports them: JPEG, PNG, GIF, WBMP, and GD2."
[2] http://en.wikipedia.org/wiki/Wireless_Application_Protocol_Bitmap_Format
Upvotes: 1