Guest_imported
New member
- Jan 1, 1970
- 0
I just started learning perl and it's GD module. I encountered a proble while trying to display a color index table with a cgi program. The problem is that the last half of codes don't function properly. I tried many ways to debug it, but can't solve it. The codes are shown as follows. If your using a Apache server, you only need to modify the path line for your perl program.
#!E:/perl/bin/perl -w
use strict;
use GD;
my $x;
my $y=50;
my $im=new GD::Image(900,5000);
my ($R,$G,$B)=(255,255,255);
my $black = $im->colorAllocate(0, 0, 0);
my $white =$im->colorAllocate(255,255,255);
$im->transparent($black);
$im->interlaced('true');
open PICFILE, ">../htdocs/pic/gd2.png" or die "Couldn't open image file: $!\n";
for($R=255;$R>=0;$R-=51){
for($G=255;$G>=0;$G-=51){
$x=50;
for($B=255;$B>=0;$B-=51){
my $fontColor=$im->colorAllocate(255-$R,255-$G,255-$B);
my $color=$im->colorAllocate($R,$G,$B);
#$im->filledRectangle($x, $y, $x+110, $y+110, $color);
$im->rectangle($x, $y, $x+110, $y+110, $fontColor);
$im->fill($x+50,$y+50,$color);
$im->string(gdLargeFont, $x+30, $y+30, "R=$R", $fontColor);
$im->string(gdLargeFont, $x+30, $y+50, "G=$G", $fontColor);
$im->string(gdLargeFont, $x+30, $y+70, "B=$B", $fontColor);
$x+=130;
}
if($G>0){
$y+=130;
}
}
if($R>0){
$y+=150;
}
}
print "Content-type: text/html\n\n";
binmode PICFILE;
print PICFILE $im->png;
print <<HTML;
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Color Index</title>
</head>
<body>
<h1 align="center">See The Following Image?</h1>
<table border="1" width="431" height="410">
<tr>
<td><IMG SRC="/pic/gd2.png">¡¡</td>
</tr>
</table>
</body>
</html>
HTML
#!E:/perl/bin/perl -w
use strict;
use GD;
my $x;
my $y=50;
my $im=new GD::Image(900,5000);
my ($R,$G,$B)=(255,255,255);
my $black = $im->colorAllocate(0, 0, 0);
my $white =$im->colorAllocate(255,255,255);
$im->transparent($black);
$im->interlaced('true');
open PICFILE, ">../htdocs/pic/gd2.png" or die "Couldn't open image file: $!\n";
for($R=255;$R>=0;$R-=51){
for($G=255;$G>=0;$G-=51){
$x=50;
for($B=255;$B>=0;$B-=51){
my $fontColor=$im->colorAllocate(255-$R,255-$G,255-$B);
my $color=$im->colorAllocate($R,$G,$B);
#$im->filledRectangle($x, $y, $x+110, $y+110, $color);
$im->rectangle($x, $y, $x+110, $y+110, $fontColor);
$im->fill($x+50,$y+50,$color);
$im->string(gdLargeFont, $x+30, $y+30, "R=$R", $fontColor);
$im->string(gdLargeFont, $x+30, $y+50, "G=$G", $fontColor);
$im->string(gdLargeFont, $x+30, $y+70, "B=$B", $fontColor);
$x+=130;
}
if($G>0){
$y+=130;
}
}
if($R>0){
$y+=150;
}
}
print "Content-type: text/html\n\n";
binmode PICFILE;
print PICFILE $im->png;
print <<HTML;
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Color Index</title>
</head>
<body>
<h1 align="center">See The Following Image?</h1>
<table border="1" width="431" height="410">
<tr>
<td><IMG SRC="/pic/gd2.png">¡¡</td>
</tr>
</table>
</body>
</html>
HTML