|
发表于 2004-4-14 18:54:50
|
显示全部楼层
下面是来自于即时即用Perl模板的光盘,给出的一个例子,仅仅能够输出需要写人文本的图片,上面的情况需要安装模块:GD和GDTextUtil,另外常用的GD库的还有GDGraph,一般用来创建描述数据变化趋势和整个画面的工具,比如:柱状图和时间的关系:)
#!/usr/bin/perl
use GD;
use GD::Text::Align;
# Create our image object
$img = new GD::Image(150,150);
# Create our text alignment object
my $align = GD::Text::Align->new($img,
valign => 'top',
halign => 'left',
);
# Build our colors
my $black = $img->colorAllocate(0,0,0);
my $white = $img->colorAllocate(255,255,255);
# Fill the image to have a white background
$img->fill(0,0,$white);
# Set our font to be GD's built in internal "small" font
$align->set_font(gdSmallFont);
# Set our text string and our color
$align->set_text("erl makes this easy!");
$align->set( color => $black);
# Actually draw the text
$align->draw(75,145,90);
# Output the image data in the usual way
my $image_data = $img->png;
open(OUTPUT, ">output4.png");
print OUTPUT $image_data;
close(OUTPUT); |
|