Hey guys i am trying to recolor the following image with php:
I want to give my user the possibility to change the color of the banner with a a few clicks in my php application. So i used this little experimental script i got here
This is my script to change one rgb color of my image:
$imgname = "test.png";
$im = imagecreatefrompng($imgname);
imagealphablending($im, false);
for ($x = imagesx($im); $x--;) {
for ($y = imagesy($im); $y--;) {
$rgb = imagecolorat($im, $x, $y);
$c = imagecolorsforindex($im, $rgb);
if ($c['red'] == 0 && $c['green'] == 94 && $c['blue'] == 173) {
$colorB = imagecolorallocatealpha($im, 255, 0, 255, $c['alpha']);
imagesetpixel($im, $x, $y, $colorB);
}
}
}
imageAlphaBlending($im, true);
imageSaveAlpha($im, true);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
The problem is the blue color of the banner are multiple different rgb colors so how can i change all blue rgb colors at once without affecting the other colors.