GD and Converting a Transparent PNG-8 to a Transparent GIF
| From: | Graham Anderson | Date: | Sun, 18 Jan 2009 07:39:52 +0000 |
| Subject: | GD and Converting a Transparent PNG-8 to a Transparent GIF | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-286581@lists.php.net to get a copy of this message | ||
Hi
I am having problems getting GD to convert a transparent PNG-8 to a transparent GIF
The below WILL produce a GIF...but leaves a white background
# Convert the PreExisting PNG Image to a GIF
$img = imagecreatefrompng($pngPath);
# Set the GIF to be transparent: Does not seem to work
$trans_color = imagecolortransparent($img );
$trans_index = imagecolorallocate($img, $trans_color['red'], $trans_color['green'], $trans_color['blue'] );
imagecolortransparent($img, $trans_index );
# Save the Image as a GIF in the directory
imagegif($img, $gifAbsolutePath);
Is there another way that works?
Many thanks in advance
G