in reply to Re: Perl GD problem
in thread Perl GD problem

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

Replies are listed 'Best First'.
Re^3: Perl GD problem
by xdg (Monsignor) on Aug 17, 2005 at 14:44 UTC

    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.

      Thanks for the advice. I have now made it to true color and am successful in getting all the lines in different color but has brought in another problem. The background has turned black. How can I correct it.

        Why not just draw a big filled rectangle, the size of your image, in white, before you start drawing anything else? Use the filledRectangle method. There may be a more clever way of doing it, but that's how I've solved this king of thing in the past!


        s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&

        From the GD documentation:

        $index = $image->colorAllocate(red,green,blue)

        This allocates a color with the specified red, green and blue components and returns its index in the color table, if specified. The first color allocated in this way becomes the image's background color. (255,255,255) is white (all pixels on). (0,0,0) is black (all pixels off). (255,0,0) is fully saturated red. (127,127,127) is 50% gray. You can find plenty of examples in /usr/X11/lib/X11/rgb.txt.

        (emphasis is mine)

        So, before your loop do:

        $im->colorAllocate(255,255,255);
        <-radiant.matrix->
        Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
        The Code that can be seen is not the true Code
        "In any sufficiently large group of people, most are idiots" - Kaa's Law