PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Nov 13, 2018 4:19 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Dec 04, 2007 4:51 am 
Offline
Forum Contributor

Joined: Mon Aug 21, 2006 7:09 am
Posts: 272
Location: Romania
I have to a couple gif that I merge after I colored the first one (or the second one). The colors of the third and fourth gif image change ("blend") with the colors of the first or second gif. I tried using imagecopy the same result.
The script is quite long so I cut some parts from it for a better reading
Syntax: [ Download ] [ Hide ]
//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;

        }

Any ideas besides replacing the functions that deal with copying (imagetruecolortopalette, imagepalettcopy) or imagecopy which don' t work.


Top
 Profile  
 
PostPosted: Wed Jan 16, 2008 4:48 am 
Offline
Forum Contributor

Joined: Mon Aug 21, 2006 7:09 am
Posts: 272
Location: Romania
I found out there is a problem if the images are gifs, if there is a jpg image the leakage will stop.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group