Re: GD and Converting a Transparent PNG-8 to a Transparent GIF

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I got it to work :)
Like you had recommended, I found a script in http://php.net/imagecolortransparent from: fmkaiba at optonline dot net
07-Feb-2008 08:05.  The function is called, createthumb

Cheers
Graham

On Jan 18, 2009, at 4:46 PM, Jochem Maas wrote:

Graham Anderson schreef:
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 );

I can't see the above code doing much useful. the problem is somewhat
more involved, png uses an alpha channel to determine how much transparency a given pixel has, with gif a pixel is either transparent or not, essentially
a given colour in the gif's palette is marked as transparent and all
pixels with that color are therefore shown as transparent.

try the code here (no idea how well it works):

	http://demo.pixelsandpages.com/php-tests/images/test.html

and/or dig into the user comments here:

	http://php.net/imagecolortransparent


# Save the Image as a GIF in the directory
imagegif($img, $gifAbsolutePath);


Is there another way that works?

Many thanks in advance

G




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux