note 83119 added to function.imagecreatefromwbmp
| From: | AeroX at aerox-studios | Date: | Sun, 11 May 2008 09:54:04 +0000 |
| Subject: | note 83119 added to function.imagecreatefromwbmp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139266@lists.php.net to get a copy of this message | ||
.bmp is just hex encoded RGB values.
All you need to do is open in binary mode and seperate the header from the body.
Decode the width and height from the header.
Then create the image pixel by pixel from the RGB values in the body.
function imagecreatefrombmp( $filename )
{
$file = fopen( $filename, "rb" );
$read = fread( $file, 10 );
while( !feof( $file ) && $read != "" )
{
$read .= fread( $file, 1024 );
}
$temp = unpack( "H*", $read );
$hex = $temp[1];
$header = substr( $hex, 0, 104 );
$body = str_split( substr( $hex, 108 ), 6 );
if( substr( $header, 0, 4 ) == "424d" )
{
$header = substr( $header, 4 );
// Remove some stuff?
$header = substr( $header, 32 );
// Get the width
$width = hexdec( substr( $header, 0, 2 ) );
// Remove some stuff?
$header = substr( $header, 8 );
// Get the height
$height = hexdec( substr( $header, 0, 2 ) );
unset( $header );
}
$x = 0;
$y = 1;
$image = imagecreatetruecolor( $width, $height );
foreach( $body as $rgb )
{
$r = hexdec( substr( $rgb, 4, 2 ) );
$g = hexdec( substr( $rgb, 2, 2 ) );
$b = hexdec( substr( $rgb, 0, 2 ) );
$color = imagecolorallocate( $image, $r, $g, $b );
imagesetpixel( $image, $x, $height-$y, $color );
$x++;
if( $x >= $width )
{
$x = 0;
$y++;
}
}
return $image;
}
----
Server IP: 87.124.64.96
Probable Submitter: 86.154.55.71
----
Manual Page -- http://www.php.net/manual/en/function.imagecreatefromwbmp.php
Edit -- https://master.php.net/note/edit/83119
Del: integrated -- https://master.php.net/note/delete/83119/integrated
Del: useless -- https://master.php.net/note/delete/83119/useless
Del: bad code -- https://master.php.net/note/delete/83119/bad+code
Del: spam -- https://master.php.net/note/delete/83119/spam
Del: non-english -- https://master.php.net/note/delete/83119/non-english
Del: in docs -- https://master.php.net/note/delete/83119/in+docs
Del: other reasons-- https://master.php.net/note/delete/83119
Reject -- https://master.php.net/note/reject/83119
Search -- https://master.php.net/manage/user-notes.php