in reply to Image Editing with GD
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Image Editing with GD
by alanonymous (Sexton) on Nov 10, 2006 at 12:36 UTC | |
by BrowserUk (Patriarch) on Nov 10, 2006 at 13:36 UTC | |
by alanonymous (Sexton) on Nov 11, 2006 at 00:27 UTC | |
by Melly (Chaplain) on Nov 10, 2006 at 13:06 UTC |