Saving other colors besides transparency from a gif
Posted: Mon Oct 22, 2007 8:04 am
I have a big problem making a php script that saves the transparency of a gif image (alpha channel). The documentation for this and code examples are some few that the script I tried modifying is very simple: it does save transparency but loses the colors in process.
I know it' s easier to save transparency for png and that the big mistake is filling with transparency the image but I didn' t found any other way. Can you help me?
Code: Select all
function trans($path){
$colorTrans=0;
$dimX=0;
$dimY=0;
$im="";
$im1="";
$imtrans="";
//get the image from disk
$im=imagecreatefromgif($path);
//dimension of the file dimX= width dimY= height
$dimX=imagesx($im);
$dimY=imagesy($im);
//create new image which saves the transparency
$imtr=imagecreatetruecolor($dimX,$dimY);
//using image copy for testing reasons
imagecopy($im,$imtr,0,0,0,0,$dimX,$dimY);
//getting the 'transparent' color
$colorTrans=imagecolortransparent($im);
//filling the background with the transparent color and saving it
imagefill($imtr,0,0,$colorTrans);
imagecolortransparent($imtr,$colorTrans);
return imagegif($imtr);
imagedestroy($imtr);
}