Using PNG-24 in PHP GD

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
unknown365
Forum Newbie
Posts: 10
Joined: Mon Jun 22, 2009 1:37 am

Using PNG-24 in PHP GD

Post by unknown365 »

Hi Everyone!
I want to use PNG-24 in GD so that I would get a better image quality.
My problem is that whenever I use PNG-24, the image that i try to call using "imagecreatefrompng" becomes a different image. Also, the image that I use has a transparent background but whenever I use the PNG-24 image, the background becomes white.

However in using a PNG-8 image, I don't encounter these two problems.

Below are the images that I used
PNG-8 (the original look of the image)
Image

PNG-24
Image

As can be seen above, the PNG-24 is totally different from the PNG-8. Please help!
unknown365
Forum Newbie
Posts: 10
Joined: Mon Jun 22, 2009 1:37 am

Re: Using PNG-24 in PHP GD

Post by unknown365 »

Can anyone please help me? :(
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Using PNG-24 in PHP GD

Post by onion2k »

My problem is that whenever I use PNG-24, the image that i try to call using "imagecreatefrompng" becomes a different image.
What do you mean by "becomes a different image"?

I imagine it'll be due to PNG-24 not having any transparency support (use PNG-32 for an alpha channel), but that's just a guess.
unknown365
Forum Newbie
Posts: 10
Joined: Mon Jun 22, 2009 1:37 am

Re: Using PNG-24 in PHP GD

Post by unknown365 »

The output picture of the PNG-8 and PNG-24 is posted above
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Using PNG-24 in PHP GD

Post by McInfo »

May I see some PHP code?

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 11:33 am, edited 1 time in total.
unknown365
Forum Newbie
Posts: 10
Joined: Mon Jun 22, 2009 1:37 am

Re: Using PNG-24 in PHP GD

Post by unknown365 »

I was already able to solve the problem but I was just wondering...does the quality of an image changes if I use GD? Because in my case, the quality of the image i used in GD suddenly had some edges. Is this normal?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Using PNG-24 in PHP GD

Post by onion2k »

unknown365 wrote:I was already able to solve the problem but I was just wondering...does the quality of an image changes if I use GD? Because in my case, the quality of the image i used in GD suddenly had some edges. Is this normal?
It will depend on your code, not GD. I imagine you're inputting a PNG-32 (or PNG-24) image, and outputting a PNG-8 image. That will end up doing nasty things because you're going from true colour to a colour palette.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Using PNG-24 in PHP GD

Post by McInfo »

For smooth edges, use imagesavealpha().

Related topic: 101361

Edit: This post was recovered from search engine cache.
Post Reply