- use GD;
- use Encode;
- use GD::Polyline;
- use constant font => '/tmp/MSYH.TTF'; #用微软雅黑字体
- my $im = new GD::Image($with,$length);
- my ($white,$black,$red,$blue,$yellow) =
- (
- $im->colorAllocate(255, 255, 255),
- $im->colorAllocate(0, 0, 0),
- $im->colorAllocate(255, 0, 0),
- $im->colorAllocate(0,0,255),
- $im->colorAllocate(255,250,205)
- );
#画横线,间隔20个像素
- for (my $i=0;$i<=$length;$i+=20)
- {
- my $line= new GD::Polyline;
- $line->addPt(0,$i); #从哪画,前面是(0,x)表示从左到右画横线
- $line->addPt($with,$i); #画多长
- $im->polyline($line,$red); #线是红色
- $im->fill(10,$i-1,$yellow) if ($i%40==0); #各行填充颜色为黄色
- # $im->fill(10,$i-1,$white) if ($i%40>0);
- $im->polyline($line,gdBrushed); #刷
- }
- #画表格的列,共6列
- my @j=(0,70,130,190,250,310,380);
- foreach my $j (@j)
- {
- my $line= new GD::Polyline;
- $line->addPt($j,0); #后面是(x,0),表示从上到下画竖线
- $line->addPt($j,$length); #从(0,0)(70,0)(130,0)往下画length长度
- $im->polyline($line,$red); #线是红色属性
- $im->polyline($line,gdBrushed);#开始刷brush
- }
- #填充单元格
$im->fill(132,62,$blue);
$im->fill(100,70,$red);
open (OUT,">$ARGV[1]");
my @out = <>;
for (my $z=0;$z<7;$z++)
{
my $n=$z*20+18;
my $m=$j[$z]+3;
my $out=decode("gb2312",$out[$z]); #编码
$im->stringTTF($black,font,10.0,0.0,$m,$n,"$out") || die $@; #写字,通过x,y定位
}
- binmode STDOUT;
- # print the image to stdout
print OUT $im->png;
close OUT;