Hello people!
My problem is as follows: I need to convert a partially transparent PNG to a transparent GIF. Everything works fine except of the background problem. You might know such thing in photoshop as "Matte" for the GIF images. So when I convert my PNG to a GIF I want to set the Matte of the image (for instance #00FF00). This means that I want to set a green background to the PNG image and then set all the parts that are absolutely equal to 00FF00 (0, 255, 0) to become transparent. Also I can't create loops running through each pixel as this loads my server with the amount of requests I have. Here is the part of the code that creates my backround:
imagealphablending($image_resized, true);
// Create a new transparent color for image
$color = imagecolorallocatealpha($image_resized,$back_color[0], $back_color[1], $back_color[2], 127);
// Completely fill the background of the new image with allocated color.
$color=imagecolorallocate($image_resized, $back_color[0], $back_color[1], $back_color[2]);
imagefill($image_resized, 0, 0, $color);
// Restore transparency blending
imagesavealpha($image_resized, true);
//$black = imagecolorallocate($image_resized, $back_color[0], $back_color[1], $back_color[2]);
// Make the background transparent
imagecolortransparent($image_resized, $color);
In the given code: if I remove the "imagefill" line the script works, but the Matte becomes black. If I enable it, background sets up perfectly, but the transparency works wrong. Can anyone tell me what is wrong?