I want to replace a color that has alpha channel with one picked by the user but saving the alpha channel in the process. I look on the web and this is done only for png images, I need for gifs and jpg images. The code I made is the common script for replacing colors in an image.
//rgb is the color picked by the user
$red=hexdec(substr($rgb,0,2));
$green=hexdec(substr($rgb,2,2));
$blue=hexdec(substr($rgb,4,2));
for($i=0;$i<imagecolorstotal($im);$i++){
$col=ImageColorsForIndex($im,$i);
$red_set=$red/255*$col['red']+$ligtht;
$green_set=$green/255*$col['green']+$ligtht;
$blue_set=$blue/255*$col['blue']+$ligtht;
if($col['alpha']<=126) {$alpha=$col['alpha'];}
}
P.S. Sorry about the formating but the Post new topic textarea message doesn' t jump to a new line when I press Enter in FF 2.0.9 .
Edit: ^ Today it works.
Last edited by Rovas on Fri Nov 30, 2007 1:26 am, edited 1 time in total.
I put some echo in the function and found out that the transparent color is correctly identified for gifs, the formula is good but I didn' t find out why is not making the image .
I changed the function a bit after I observed that in gif image the last color is the one with the transparent pixels, added the header for the image but it still doesn' t save transparency and for some images it omits some parts of it.
I made it work by removing some echo that I forgot to comment . But it only works for some gifs while for others it puts transparent pixels where there aren' t in the original (i. e. changes their alpha channel) .