PHP Developers Network

Palette images and transparency
Page 1 of 1

Author:  bonzairob [ Sat Jul 09, 2011 2:21 pm ]
Post subject:  Palette images and transparency

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:
Syntax: [ Download ] [ Hide ]
$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!

Author:  McInfo [ Mon Jul 11, 2011 10:19 pm ]
Post subject:  Re: Palette images and transparency

The GIF seems to be created correctly with this line removed.
Syntax: [ Download ] [ Hide ]
imagetruecolortopalette($imtc, false, 32);

I don't see any benefit to calling the function.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group