Hi
I think you have to use fread to load the binary file, here is a quick 
function that will do what you want. It a little bit safer than just 
blindly changing hex values in the file, it only checks the colour table.
Tom

<?php

function change($file,$r,$g,$b,$r2,$g2,$b2){
         $found = 0;
         if($fd = fopen($file, "r")):
                 $f = fread($fd, filesize ($file));
                 fclose ($fd);
                 $gif = unpack("C*",$f);
                 $flag = $gif[11];       //flag position
                 if($flag & 128): //we have a global table
                         $colours = pow(2,($flag & 7)+1);        //number 
of entries in table
                         $x = 14;                //start of global table
                         $y = $x + (3 * $colours);       //3 bytes per colour
                         while($x < $y):
                                 if(($gif[$x] == $r)&&($gif[$x+1] == $g) && 
($gif[$x+2] == $b)):
                                         echo "found colour  at offset $x 
<br>";
                                         $gif[$x] = $r2;
                                         $gif[$x+1] = $g2;
                                         $gif[$x+2] = $b2;
                                         $found = 1;
                                 endif;
                                 $x +=3;
                         endwhile;
                 endif;
         endif;
         if($found == 1):
                 while(list($key,$val)=each($gif)):
                         $newgif .= pack("C",$val);
                 endwhile;
                 $fd = fopen("test.gif", "w");
                 fwrite($fd,$newgif);
                 fclose($fd);
         endif;
}
$filename = "vcd_1.gif";
change($filename,0xff,0x33,0x66,0x33,0x45,0xff);
?>
<img src="vcd_1.gif" width="259" height="32" alt="" border="0"><br>
<img src="test.gif" width="259" height="32" alt="" border="0">







At 05:06 PM 5/06/2002, johannes reichardt wrote:
>hi everybody, i am new to this list & php
>and i have a big question that i would love to be answered ;)
>
>i have a small gif file that has a part in #ff3366 colored - so what i
>thought
>is to do a mean hack for my website: instead of opening all images in a
>graphicseditor and change the
>color manually i could look up for that color (ff3366) in the image files
>and replace it with something else, unfortunatly
>i got stuck with this approach pretty soon. here is my problem:
>
>if i open the gif file in php (its attached to this mail) and convert it to
>hex:
>
>$filetext1 = implode("",(@file("vcd_1.gif")));
>$filetext1 = bin2hex($filetext1);
>  }
>
>like this i get a string that looks like hex - but i cant find my ff3366
>anymore,
>did i miss something really obvious?
>
>if i look up the gif file with an hexeditor (i use textpad) i can see it -
>with php
>its not findable
>
>any ideas?
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to