Transparent image resizing using php 4.4.x

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux