"jisatsusha" <ji******@yahoo.co.uk> wrote in message
news:2j*************@uni-berlin.de...
dan glenn wrote: (PHP4.3.4, GD2) How can I save a PNG using GD2 and insure that it saves
as a palette-based (8-bit, 256-color) single-color transparancy?? Saving this
way, I could be sure that an image loaded from a transparent gif could
be saved as a png and the png would work in IE versions 5.5 and greater (IE
has bug that messes up png transparancies which use full alpha channel).
thanks for any help at all,
-dg
Using imagecreate() and imagecolortransparent() should do the trick.
You're guessing. But you got me closer. Here's sample code of what I have
now, which still isn't quite working ('somegiffile.gif' is a gif with
transparancy):
1) $orig_img = @imagecreatefromgif("somegiffile.gif");
2) $trans_colorIndex = imagecolortransparent($orig_img); // (this works)
3) $x = imagesx($orig_img); // get size in x
4) $y = imagesy($orig_img); // get size in y
5) $pngimg = @imagecreate($x,$y); // create 8-bit palette-based blank image
6) imagepalettecopy($pngimg,$orig_img); // (didn't maintain sameness in
palettes)
7) imagecopy($pngimg,$orig_img,0,0,0,0,$x,$y); // (works fine)
8) imagecolortransparent($pngimg,255); // (doesn't do anything!)
9) imagepng($pngimg,"somegiffile.png"); // save to png file
This succeeded in giving me a good .png with an 8-bit (256-color) pallette,
but the transparancy was coming out solid BLACK (no transparancy and
different color than used for original's transparancy color). Line 2) above
worked - gave correct index to transparant color in original gif pallette.
Line 6) was an attempt to get the two palettes looking the same, as I
discovered that the order of the colors in the palette of the result png was
totally different from the order in the original gif, but putting this line
in had no effect - palette order still completely different. But I did
notice that in copying over the image, the imagecopy() function put what was
the transparent color LAST in the palette, BUT it made it BLACK instead of
the original (which was red in my test file) - probably a carry-over from
the original imagecreate() which had everything black. That's why in line
8), I use "255" for the transparancy index instead of the $trans_colorIndex
read earlier. The problem now is, line 8) fails to set the transparancy. So
the PNG just renders the background as BLACK. If I use a graphics program on
the result to set the transparancy to index 255, the resulting PNG works
fine in IE.
Any suggestions?