image - imagecreatefrombmp not working on php -


i trying half size of bmp image php. pho gd doesnt have imagecreatefrombmp have include seperate function. code doesnt seems working. works jpeg. here code should display half image of bmp image test.bmp

<?php   if (!function_exists("imagecreatefrombmp")) {     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 stuff?             $header = substr( $header, 32 );             // width             $width = hexdec( substr( $header, 0, 2 ) );             // remove stuff?             $header = substr( $header, 8 );             // height             $height = hexdec( substr( $header, 0, 2 ) );             unset( $header );         }         $x = 0;         $y = 1;         $image = imagecreatetruecolor( $width, $height );         foreach( $body $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;     } } // file , new size $filename = 'wheat.bmp'; $percent = 0.5;  // content type header('content-type: image/bmp');  // new sizes list($width, $height) = getimagesize($filename); $newwidth = $width * $percent; $newheight = $height * $percent;  // load $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefrombmp($filename);  // resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);  // output imagejpeg($thumb); ?> 

try imagecreatefromwbmp(). right function convert images bmp file.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -

jquery - How can I dynamically add a browser tab? -