Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

GD color limit is too low



10:11 pm on Apr 3, 2011 (gmt 0)

5+ Year Member

I just started learning about the GD library and made a small script to test a few features. I quickly found out that I was limited to 256 colors, but that creating the image with imagecreatetruecolor() instead of imagecreate() all but eliminates the issue. However, after a few modifications I saw the 256 color limit reappear, even though I am still using imagecreatetruecolor(). What is causing this and how do I fix it?

Here's my testing / playing around script. You'll notice that if you set the number of line segments (for loop's upper bound) to greater than 256 the line appears increasingly disjointed. This is because the rest of the line in being drawn in the background color, black.

for($i=0;$i<1000;$i++) {
if($x<0) {
if($x>=$s) {
if($y<0) {
if($y>=$s) {


4:28 pm on Apr 28, 2011 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

The RGB components cannot go beyond that value:

These parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF.



9:59 pm on Apr 28, 2011 (gmt 0)

5+ Year Member


Your script is, in some instances, calling
with the third argument (green) as a negative number, this causes
to return false, which
is interpreting as black.
Also you're always setting the red argument to 0 which will limit you range of colours.



7:36 pm on Apr 29, 2011 (gmt 0)

5+ Year Member

Well that's embarrassing. Thanks for your replies though, and hopefully next time I'll wait a little longer before asking for help.


9:28 pm on Apr 29, 2011 (gmt 0)

5+ Year Member

Don't worry can't-see-the-wood-for-the-trees syndrome is common amongst programmers, I know because I sometimes struggle with the condition myself.


Featured Threads

Hot Threads This Week

Hot Threads This Month