PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Nov 22, 2014 11:34 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Jul 09, 2011 2:21 pm 
Offline
Forum Newbie

Joined: Sat Jul 09, 2011 2:13 pm
Posts: 1
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!


Top
 Profile  
 
PostPosted: Mon Jul 11, 2011 10:19 pm 
Offline
DevNet Resident
User avatar

Joined: Wed Apr 01, 2009 1:31 pm
Posts: 1531
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group