PDA

View Full Version : Problem while using imagecreatefromwbmp


garrisonian14
06-11-2008, 01:56 PM
Hi friends,

As we use imagecreatefromjpeg for jpg images and imagecreatefromgif for gif images. Which function i can user from bmp images.

If your answer is imagecreatefromwbmp , then i have used it, but it generates error for bmp images "test.bmp is not a valid WBMP file".

Please suggest me, how can i solve this problem.

Thanks to all.

Mwnciau
06-11-2008, 02:53 PM
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;
}

From the php manual. (http://uk3.php.net/manual/en/function.imagecreatefromwbmp.php#83119)

Inigoesdr
06-11-2008, 05:33 PM
Hi friends,

As we use imagecreatefromjpeg for jpg images and imagecreatefromgif for gif images. Which function i can user from bmp images.

If your answer is imagecreatefromwbmp , then i have used it, but it generates error for bmp images "test.bmp is not a valid WBMP file".

Please suggest me, how can i solve this problem.

Thanks to all.
"WBMP" is not "BMP". They are completely different formats. PHP's GD module doesn't have a native function to create bitmaps. Use a custom function from the manual's comments like the one Mwnciau posted.