I an trying to change color of a png image so that transparent area still remain transparent and give rest of the image a color this is what i tried
<?php
$im = imagecreatefrompng('2.png');
$w = imagesx($im);
$h = imagesy($im);
$om = imagecreatetruecolor($w,$h);
for ($x = 0; $x < $w; $x++) {
for ($y = 0; $y < $h; $y++) {
$rgb = imagecolorat($im, $x, $y);
$colors = imagecolorsforindex($im, $rgb);
$orgb = imagecolorallocate($om,$colors['alpha'],$colors['alpha'],$colors['alpha']);
imagesetpixel($om,$x,$y,$orgb);
}
}
header('Content-Type: image/png');
imagepng($om);
imagedestroy($om);
imagedestroy($im);
?>
It produce image like: Before
After
i am still not getting an exact idea how can i get highlighted area of png image and give them a color such as yellow or pink without loosing transparency so that only non-transparent area will get remain transparent