chakkaln has asked for the wisdom of the Perl Monks concerning the following question:

Dear All,

I am faced with a Problem related perl GD. I am generating random colors and using it to draws lines and polygons in a loop. What I observed was after certain number of cycles, the line color allocated is not changing. I tried to print the output of RGB which appears to be all different. I was wondering whether there is any limit in size in using the colorAllocate method (if so how can I handle the issue)or is there any thing wrong in the way I am implicating it. The following code would reproduce the problem. Thanks for your attention. Please note that I am new to GD. Nagesh

#!/usr/local/bin/perl use GD; $im = new GD::Image(1000,20); $ctr =0; $x=0; $y=10; while ($ctr <1000) { $randomRed=int(rand(256))+0; $randomGreen=int(rand(256))+0; $randomBlue=int(rand(256))+0; $getColor=$im->colorAllocate($randomRed,$randomGreen,$randomBlue); $im->line($x,$y+5,$x,$y-5,$getColor); $x++; $ctr++ } print $im->png;

Replies are listed 'Best First'.
Re: Perl GD problem
by ikegami (Patriarch) on Aug 17, 2005 at 14:22 UTC
    Doesn't GD only support 256 colours, or has that changed? Check the docs.
      I thought we can use 256 colors any number of times which is the case. I am not aware of the limit of 256 colors as this is the first time I am using GD. Does this mean that we cannot use more than 256 times Thanks

        You may need to switch from a color palette to true color mode. See the GD docs.

        GD::Image->trueColor(1);

        -xdg

        Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.