I have been tweaking more of the tiny code snippet that I have been working on (thanks again to
myocom for the original snippet.
Currently, it works fine, but I would like to know if there is a way I can make the pixel size a lot bigger or smaller. Can GD do this? I have read through the documentation at Lincoln Stein's site where the module comes from, but it doesn't seem to have any additional commands for the "setpixel" command.
Here is the current code snippet:
#!/usr/bin/perl -w
use strict;
use GD;
my ($width, $height) = (300,50);
my ($rvalue, $gvalue, $bvalue, $total) = (255,255,255,256);
my $im = new GD::Image($width,$height);
#Allocate the colors that are going to be used
my @colors;
for (0..255) {
$colors[$_] = $im->colorAllocate(int(rand($rvalue)),int(rand($gvalue
+)),int(rand($bvalue)));
}
# Create image according to height/width proportions and given amount
+of colors
for my $width_length (0..$width-1) {
for my $height_length (0..$height-1) {
$im->setPixel($width_length,$height_length,$colors[int(rand($t
+otal))]);
}
}
# Set binmode to STDOUT
binmode STDOUT;
# Set output to be an image for CGI
print "Content-Type: image/png\n\n";
# Standard output of created image
print $im->png;
Andy Summers
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.