Page 1 of 1

Palette images and transparency

Posted: Sat Jul 09, 2011 2:21 pm
by bonzairob
Hey there, I'm having trouble with what should be a simple process: Converting palette PNGs to (palette-only) GIFs.

There seem to be craploads of problems to do with resizing and rotating them, but I haven't come across anythong like my current problem: The alpha is off by one pixel, in the x axis only.

Here's the code:

Code: Select all

$im = imagecreatefrompng($_FILES['uploadedfile']['tmp_name']);	
$sizes = getimagesize($_FILES['uploadedfile']['tmp_name']);
$imtc = imagecreatetruecolor($sizes[0], $sizes[1]);
$transparent = imagecolorallocate($imtc, 255, 0, 255);
imagefilledrectangle($imtc, 0, 0, $sizes[0], $sizes[1], $transparent);
imagecopy($imtc, $im, 0, 0, 0, 0, $sizes[0], $sizes[1]);
imagecolortransparent($imtc, $transparent); //files output here are not transparent at all
imagetruecolortopalette($imtc, false, 32);
imagegif($imtc, 'result.gif'); //this file's alpha is correct other than being x+1.
And the images (fake pokemon sprites, haha):
Input: Image
Output: Image

This seems to be a byproduct of the imagetruecolortopalette function as noted above.

Could I alter the pixel data itself? Would it matter? Thanks a lot for any help!

Re: Palette images and transparency

Posted: Mon Jul 11, 2011 10:19 pm
by McInfo
The GIF seems to be created correctly with this line removed.

Code: Select all

imagetruecolortopalette($imtc, false, 32);
I don't see any benefit to calling the function.