Difference between revisions of "Perl GD/Pixel manipulation"
From Teknologisk videncenter
< Perl GD
m (New page: Playing with pixels. The script below makes this png picture. thumb|400px|Greyscale from 0 to 255 <source lang=perl> #!/usr/bin/perl use GD; use GD::Image; # crea...) |
m |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Playing with pixels. The script below makes this png picture. | Playing with pixels. The script below makes this png picture. | ||
− | [[Image:Heth.png|thumb| | + | {| |
+ | |[[Image:Heth.png|thumb|left|300px|Greyscale from 0 to 255]] | ||
+ | |[[Image:Heth2.png|thumb|300px|Using the equation @grey[ (sin($i/32)*$j) % 256 ] ]] | ||
+ | |} | ||
<source lang=perl> | <source lang=perl> | ||
#!/usr/bin/perl | #!/usr/bin/perl | ||
Line 30: | Line 33: | ||
print FILE $im->png; | print FILE $im->png; | ||
</source> | </source> | ||
− | |||
[[Category:Perl]] | [[Category:Perl]] |
Latest revision as of 11:59, 23 January 2011
Playing with pixels. The script below makes this png picture.
#!/usr/bin/perl
use GD;
use GD::Image;
# create a new image
$im = new GD::Image(640,480);
#Grey scale
my @grey;
for (my $i = 0; $i <=255; $i++) {
$grey[$i] = $im->colorAllocate($i,$i,$i);
}
print "Allocated ", $#grey+1, " colors\n";
for( my $i=0; $i<=640-1 ;$i++ ) {
for( my $j=0; $j<=480-1;$j++ ) {
$im->setPixel($i,$j,@grey[ ($i+$j) % 256 ]);
#$im->setPixel($i,$j, $c[($i+$j)%4]);
}
}
print "Der er ialt ", $im->colorsTotal(), " farver\n";
# Convert the image to PNG and save it.
open FILE,'> C:\temp\heth.png';
binmode FILE;
print FILE $im->png;