【发布时间】:2013-06-16 21:48:50
【问题描述】:
gd.pl
#!/usr/bin/perl -w
use strict;
use GD;
my $image = GD::Image->newPalette(401,201);
my $gray = $image->colorAllocate(200,200,200);
my $red = $image->colorAllocate(255,0,0);
my $black = $image->colorAllocate(0,0,0);
#draw a field of polka dots with random diameters
foreach my $i (0..10) {
foreach my $j (0..5) {
my $d = rand(50)+1;
$image->arc($i*40, $j*40, $d, $d, 0, 360, $red);
$image->fill($i*40, $j*40, $red);
}
}
#draw the text in black
my ($x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4) = $image->stringFT($black, "/home/eugenep/arial.ttf", 48,0,40,120, "hello world");
#outline the text with a black box
$image->rectangle($x1-10, $y1+10, $x3+10, $y3-10, $black);
print $image->png;
它没有显示任何东西,而是在命令提示符下显示一堆奇怪的字符。
谁能告诉我可能是什么问题?
【问题讨论】:
-
您是否尝试过将图像写入文件,然后用可以理解 PNG 的文件打开该文件?你的控制台只是在做你要求它做的事情。
-
哦,有道理。我不知道 perl 是否类似于 java,当我执行 GD::Image->newPalette(401,201) @muistooshort 时它会自动创建 jframe ish