note 63689 added to ref.image
| From: | shd at earthling dot net | Date: | Tue, 28 Mar 2006 12:44:43 +0000 |
| Subject: | note 63689 added to ref.image | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106841@lists.php.net to get a copy of this message | ||
If you happen to need a way to output a Windows BMP file (e.g. when using the PEAR ExcelWriter),
feel free to use the following code:
<?php
function imagebmp ($im, $fn = false)
{
if (!$im) return false;
if ($fn === false) $fn = 'php://output';
$f = fopen ($fn, "w");
if (!$f) return false;
//Image dimensions
$biWidth = imagesx ($im);
$biHeight = imagesy ($im);
$biBPLine = $biWidth * 3;
$biStride = ($biBPLine + 3) & ~3;
$biSizeImage = $biStride * $biHeight;
$bfOffBits = 54;
$bfSize = $bfOffBits + $biSizeImage;
//BITMAPFILEHEADER
fwrite ($f, 'BM', 2);
fwrite ($f, pack ('VvvV', $bfSize, 0, 0, $bfOffBits));
//BITMAPINFO (BITMAPINFOHEADER)
fwrite ($f, pack ('VVVvvVVVVVV', 40, $biWidth, $biHeight, 1, 24, 0, $biSizeImage, 0, 0,
0, 0));
$numpad = $biStride - $biBPLine;
for ($y = $biHeight - 1; $y >= 0; --$y)
{
for ($x = 0; $x < $biWidth; ++$x)
{
$col = imagecolorat ($im, $x, $y);
fwrite ($f, pack ('V', $col), 3);
}
for ($i = 0; $i < $numpad; ++$i)
fwrite ($f, pack ('C', 0));
}
fclose ($f);
return true;
}
?>
It works the same way as regular imagejpeg/imagepng do and only supports GD2.0 true colour bitmaps
(which is what's required by ExcelWriter).
----
Server IP: 83.137.20.120
Probable Submitter: 213.84.83.41
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/ref.image.php
Edit -- http://master.php.net/note/edit/63689
Del: integrated -- http://master.php.net/note/delete/63689/integrated
Del: useless -- http://master.php.net/note/delete/63689/useless
Del: bad code -- http://master.php.net/note/delete/63689/bad+code
Del: spam -- http://master.php.net/note/delete/63689/spam
Del: non-english -- http://master.php.net/note/delete/63689/non-english
Del: in docs -- http://master.php.net/note/delete/63689/in+docs
Del: other reasons-- http://master.php.net/note/delete/63689
Reject -- http://master.php.net/note/reject/63689
Search -- http://master.php.net/manage/user-notes.php