The script is quite long so I cut some parts from it for a better reading
Code: Select all
//creating the image resources the simple imagegif($path);
/*this condition checks that the resource is transparent and has a color. Applies the selected color to the image using a function defined lower and the merges with the first one */
if($transparent2==1 && $rgb2!=""){$im2=ImageColorWithTransparency($im2, $rgb2); imagecopymerge($im1,$im2, $x2, $y2, 0,0, imagesx($im2), imagesy($im2), 100);}
if($transparent3==1 && $rgb3!=""){$im3=ImageColorWithTransparency($im3, $rgb3); imagecopymerge($im1,$im3, $x3, $y3, 0,0, imagesx($im3), imagesy($im3), 100);}
//and so on ...
//for saving the transparent gifs the function trans must used
$transparentImage=trans($im1);
imagegif(transparentImage);
//this function colores a transparent gif and saves it' s transparency
function ImageColorWithTransparency($im, $rgb){
//extracting values for each RGB channel
$red=hexdec(substr($rgb,0,2));
$green=hexdec(substr($rgb,2,2));
$blue=hexdec(substr($rgb,4,2));
$t = imagecolorstotal($im);
//obtaining the new colors using the formula
for($i=0;$i<=$t-1;$i++){
$col=ImageColorsForIndex($im,$i);
$red_set=$red/255*$col['red'];
$green_set=$green/255*$col['green'];
$blue_set=$blue/255*$col['blue'];
if($red_set>255)$red_set=255;
if($green_set>255)$green_set=255;
if($blue_set>255)$blue_set=255;
if($red_set<0)$red_set=0;
if($green_set<0)$green_set=0;
if($blue_set<0)$blue_set=0;
//coloring the image with the new color
imagecolorset($im,$i,$red_set,$green_set,$blue_set);
}
return $im;
}
//this function saves the transparency of gif
function trans($im){
$culoareTrans=0;
$dimX=0;
$dimY=0;
$imtrans="";
$dimX=imagesx($im);
$dimY=imagesy($im);
//creating true color image to save transparent color
$imtr=imagecreatetruecolor($dimX,$dimY);
//copying the color from palette image
imagepalettecopy($im, $imtr);
//saving the transparent color
$culoareTrans=imagecolortransparent($im);
//filing and setting the transparent color to the new image
imagefill($imtr,0,0,$culoareTrans);
imagecolortransparent($imtr,$culoareTrans);
//copying the image
imagecopyresized($imtr, $im,0,0,0,0, $dimX, $dimY,$dimX,$dimY);
//transforming into palette
imagetruecolortopalette($imtr,true,256);
//imagecolortransparent($imtr,$culoareTrans);
return $imtr;
}