I wrote a coding for replacing color of PNG image according to the given color. Now it is work fine. But problem is it will getting annoying when I use transparent background PNG image. it means that when I apply a color that color will apply for my whole image. not for selected colored object. But it worked fine when I used normal PNG image.
My code:
<?php
$im = imagecreatefrompng("lifestyle_noTrance.png");
$size = getimagesize("lifestyle_noTrance.png");
$L=$size[0];
$H=$size[1];
for($j=0;$j<$H;$j++){
for($i=0;$i<$L;$i++){
$rgb = imagecolorat($im, $i, $j);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >>

& 0xFF;
$b = $rgb & 0xFF;
//Turn off transparency blending
//Create a new transparent color for image
if($r=='0' && $g=='0' && $b=='0'){
$color = imagecolorallocatealpha($im, 255, 0, 0, 127);
}
else{
$color = imagecolorallocatealpha($im, $r, $g, $b, 127);
}
imagesetpixel($im, $i, $j, $color);
//Restore transparency blending
imagesavealpha($im, true);
}
}
header('content-type: image/png');
imagepng($im);
?>
Please help me, What may be the problem of my codding ?
