By default, for backwards compatibility with earlier versions of GD, images are created as 8-bit palletised. To get 24-bit color (truecolor), you need to indicate that you want this when you create the image, or afterwards using the $img->truecolor( 1 ); method.

Change your image creation line to

my $outpizzle = GD::Image->new( $width, $height, 1 );

and observe the difference it makes to your output.

Also, faking #use strict; serves no purpose whatsoever :) It took all of 10 seconds to do it properly.

#!/usr/bin/perl use strict; use GD; my $width = 800; my $height = 600; my $outpizzle = new GD::Image( $width, $height, 1 ); #$outpizzle->interlaced('true'); #define a $%!@ ton of colors ... bad idea? my @colors; for ( my $i=0; $i<10; $i++) { for ( my $j=0; $j<10; $j++) { for ( my $k=0; $k<10; $k++) { $colors[$i][$j][$k] = $outpizzle->colorAllocate($i*25,$j*2 +5,$k*25); } } } #draw some shizzle for ( my $i=0; $i<$width; $i++) { for ( my $j=0; $j<$height; $j++) { $outpizzle->setPixel($i,$j,$colors[int(10*($i/$width))][int(10 +*($j/$height))][0]); #print int(10*($i/$width))+"\n"; } } #output the picture open(PICTURE, ">picture.png") or die("uh oh spaghettio"); binmode PICTURE; print PICTURE $outpizzle->png; close PICTURE; ## display result on win32 systems system 'picture.png';

There are lots of other things that could be 'improved', but it's your code.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Image Editing with GD by BrowserUk
in thread Image Editing with GD by alanonymous

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.