Keeping background transparency when converting to GIF
[email protected] (Jason Young) Sun, 25 Jan 2009 21:45:48 -0500
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I'm having a tough time keeping transparency intact when using
imagegif() on a transparent image.
The image is definitely transparent, as evidenced when using the PNG
format .. but once I imagegif() it, the background takes on my
transparent color, minus the transparency.
Is there something different I could do to make this work as desired?
Thanks!
-Jason Young
Brief example:
<?php
$font = 'verdana.ttf';
$im = imagecreatetruecolor(100, 50);
imagesavealpha($im, true);
$trans = imagecolorallocatealpha($im, 20, 50, 50, 127); // To
demonstrate non-transparent color
$black = imagecolorallocate($im, 0, 0, 0);
imagefill($im, 0, 0, $trans);
imagettftext($im, 10, 0, 20, 20, $black, $font, 'A transparent
background?');
//header('Content-Type: image/png');
// imagepng($im); // This works as expected.
header('Content-Type: image/gif');
imagegif($im); // This does not.
imagedestroy($im);
?>