Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Color display with GD module

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
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=&quot;Content-Language&quot; content=&quot;en-us&quot;>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot;>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 4.0&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
<title>Color Index</title>
</head>

<body>

<h1 align=&quot;center&quot;>See The Following Image?</h1>
<table border=&quot;1&quot; width=&quot;431&quot; height=&quot;410&quot;>

<tr>
<td><IMG SRC=&quot;/pic/gd2.png&quot;>¡¡</td>
</tr>
</table>

</body>

</html>
HTML

 
I think you are running out of font colors. When I put in a debug statement that prints out font colors, it shows that the color is getting set to -1 right where your table breaks. If I set the font to a constant value, it seems to work fine.

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top