Page 1 of 1

Imagecolorallocate() only 256 colors! What if I want more?

Posted: Tue Apr 06, 2010 12:03 pm
by gth759k
So I've been working with imagecolorallocate() for a while now. I've made a few really helpful scripts that allow me to make just one image in photoshop, for instance an image used for a tab in a website, and then I can specify a hex color and I can make my tab image show up in the browser as any color I want without going back to photoshop. This script checks to see if a color is already allocated and only allocates a new color if it hasn't already been allocated yet like this:

Code: Select all

$color = imagecolorexact($im, $r, $g, $b);
if($color==-1) {
	$color = imagecolorallocate($im, $r, $g, $b);
}
Now I'm working on a much bigger project and I need to allocate 16.7 million colors. Can you create more than one color palette for a single image? I would need like 3600 color palettes for a 720p image. :( Would I have to allocate 256 colors and then save them somehow? Like, maybe I could break the image up into 16x16 px squares and then recombine the pieces. Any help would be appreciated. Thanks.

Re: Imagecolorallocate() only 256 colors! What if I want mor

Posted: Tue Apr 06, 2010 12:30 pm
by mikosiko
Maybe this can help you:

taken from the ImageCreateTrueColor function manual.

"ImageCreateTrueColor is used to create an image resource with an unlimited number of colors, which is useful when manipulating JPEG images, for example.

ImageCreate is used to create an image resource with a 256 color palette, sometimes called indexed color.

In previous versions, ImageCreate worked OK for manipulating JPEG images. But in experimenting with the Win32 version of PHP 4.0.6, which I think relies on the GD 2.0.1 lib beta, you have to use ImageCreateTrueColor to get accurate color results with JPEGs."

Re: Imagecolorallocate() only 256 colors! What if I want mor

Posted: Tue Apr 06, 2010 12:48 pm
by gth759k
That's what I needed! Thank you!