#!/usr/bin/perl -w
use strict;
use warnings;
use CGI;
use GD;
my $query = new CGI;
print $query->header;
print $query->start_html("EasyPX Generator");
print "<H1>EasyPX Generator</H1>\n";
prompt($query);
go_for_it($query);
print $query->end_html;
sub prompt {
my($query) = @_;
print $query->startform;
print "Enter Image File Name ";
print $query->textfield('name'),"<br>";
print "Enter Width ";
print $query->textfield('width'),"<br>";
print "Enter Height ";
print $query->textfield('height'),"<br>";
print "Enter Red Hex Value ";
print $query->textfield('red_value'),"<br>";
print "Enter Green Hex Value ";
print $query->textfield('green_value'),"<br>";
print "Enter Blue Hex Value ";
print $query->textfield('blue_value'),"<br>";
print "<p>",$query->reset;
print $query->submit('Action','Submit');
print $query->endform;
print "<hr>\n";
}
sub go_for_it {
my($query) = @_;
my(@values,$key);
print "<H2>Completed with the following values.</H2>";
foreach $key ($query->param) {
print "<STRONG>$key</STRONG> -> ";
@values = $query->param($key);
print join(", ",@values),"<BR>\n";
if ($key =~ /name/i) {
our $name = $query->param($key);
} elsif ($key =~ /width/i) {
our $width = $query->param($key);
} elsif ($key =~ /height/i) {
our $height = $query->param($key);
} elsif ($key =~ /red/i) {
our $red = $query->param($key);
$red = oct "0x" . $red;
} elsif ($key =~ /green/i) {
our $green = $query->param($key);
$green = oct "0x" . $green;
} elsif ($key =~ /blue/i) {
our $blue = $query->param($key);
$blue = oct "0x" . $blue;
}
}
my $im = new GD::Image(our $width,our $height);
my $color = $im->colorAllocate(our $red,our $green,our $blue);
$im->fill(1,1,$color);
open IMAGE, ">" . our $name . ".png";
print IMAGE $im->png();
close IMAGE;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.