Hi, I have a 32-bit true-color image where all pixels have some degree of transparency. There are just 11 different colors (i.e. 11 different combinations of RGB & alpha). When I try to convert to a palette .PNG using the code below, the transparency is lost and all pixels become opaque. Is there something wrong with the ImageTrueColorToPalette function or am I doing something stupid. Thanks.

   
..... imagealphablending($bigImageHandle, false); imagesavealpha($bigImageHandle, true); imagetruecolortopalette($bigImageHandle, false, 16); imagepng( $bigImageHandle, "filename.png", 9);

    Thanks sneakyimp, I tried adding in the extra 'imagecopyresampled' etc but it had no effect. I can manipulate the image with transparency fine, and if I save it as a 32-bit PNG it works fine. Its just the convertion to a palette PNG where the transparency is getting lost.
    I think maybe the GD library has many bugs with transparency.

      the docs for [man]imagetruecolortopalette[/man] have a somewhat glum description :

      imagetruecolortopalette() converts a truecolor image to a palette image. The code for this function was originally drawn from the Independent JPEG Group library code, which is excellent. The code has been modified to preserve as much alpha channel information as possible in the resulting palette, in addition to preserving colors as well as possible. This does not work as well as might be hoped. It is usually best to simply produce a truecolor output image instead, which guarantees the highest output quality. 

      I'm thinking that might indeed be where your problem is, but I'm no expert in the gory detail of these functions.

        Write a Reply...