Limiting Color Palette In PNG Image

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
phd1969
Forum Newbie
Posts: 1
Joined: Sun Nov 20, 2005 12:57 am

Limiting Color Palette In PNG Image

Post by phd1969 »

Hi,

I'm just wondering if there's a way to limit the color palette of a png image, ie from 256 to 16. I know imagejpeg() function has the quality attribute so I can change the quality of a jpeg from 80 to 20 but see that imagepng() has nothing.

Just wondering if there's a way to limit colors, much appreciated.

Thanks
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

imagetruecolortopalette() has an option to set the number of colours .. if you copied the image into a true colour GD resource, and then set changed that to a 16 color palette you might be ok. Otherwise you're going to have to change the colors using the imagecolorat() and imageallocatecolor() functions..

Note.. the manual comments for imagetruecolortopalette() mention it sometimes doesn't generate the best possible palette.
Post Reply