Transparent image resizing using php 4.4.x

From: Date: Sat, 09 Jun 2007 20:12:38 +0000
Subject: Transparent image resizing using php 4.4.x
Groups: php.general 
Request: Send a blank email to php-general+get-256456@lists.php.net to get a copy of this message
I have tried many ways to resize a transparent gif but it works on my local server which has php 5.1.6 but none works using php 4.4.x Also the below works when using imagecopyresized and not imagecopyresampled. I have no clue why that is the case as imagecopyresampled is supposed to produce better results. I have php version 5.1.6 locally (windows) and this works: <?php $img_resized = ImageCreateTrueColor ($img_new_width, $img_new_height); // new image to create $o_img = ImageCreateFromGif($source_file_path); // source file $trans_arr = get_transparency($source_file_path); // function given below if (isset($trans_arr['red']) && isset($trans_arr['green']) && isset($trans_arr['blue'])) {
       $transparent = imagecolorallocate($img_resized, $trans_arr['red'], $trans_arr['green'], $trans_arr['blue']);
       imagefilledrectangle($img_resized, 0, 0, $img_new_width, $img_new_height, $transparent);
       imagecolortransparent($img_resized, $transparent);
} // I tried follwoing instead of that get_transparency function and above codee. But same result /*$transparent = imagecolorallocate($img_resized, 255, 255, 255); imagefilledrectangle($img_resized, 0, 0, $img_new_width, $img_new_height, $transparent);
imagecolortransparent($img_resized, $transparent);      */
imagecopyreresized($img_resized, $o_img, 0 , 0 , 0 , 0, $img_new_width, $img_new_height, $img_orig_width, $img_orig_height); ImageGif($img_resized, $new_file_path); // this function I created by copying code from somewhere on internet function get_transparency($img_file) {
       $ret = array();
       $fp = fopen($img_file, "rb");
       $result = fread($fp, 13);
       $colorFlag = ord(substr($result,10,1)) >> 7;
       $background = ord(substr($result,11));
       if ($colorFlag)
       {
               $tableSizeNeeded = ($background + 1) * 3;
               $result = fread($fp, $tableSizeNeeded);
               $ret['red'] = ord(substr($result, $background * 3, 1));
               $ret['green'] = ord(substr($result, $background * 3 + 1, 1));
               $ret['blue'] = ord(substr($result, $background * 3 + 2, 1));
       }
       fclose($fp);
       return $ret;
} ?> But the above doesn't work using php 4.4.x and creates images with lots of white lines/dots in it. Some pixel is transparent and some it isn't. I have no knowedge about image manuplation like alpha channels etc. Could anyone please provide me a solution which works using php 4.4.x Sukhwinder Singh

« previous php.general (#256456) next »