作者sqrt1089 (李崩子)
看板Perl
标题[问题] GD图存在哪
时间Mon Oct 18 13:18:34 2010
以下是我从cpan网站的范例抓下来的
http://search.cpan.org/~lds/GD-2.45/GD.pm
#!/usr/local/bin/perl -w
use strict;
use GD;
my $im = new GD::Image(100,100);
my $white = $im->colorAllocate(255,255,255);
my $black = $im->colorAllocate(0,0,0);
my $red = $im->colorAllocate(255,0,0);
my $blue = $im->colorAllocate(0,0,255);
$im->transparent($white);
$im->interlaced('true');
$im->rectangle(0,0,99,99,$black);
$im->arc(50,50,95,75,0,360,$blue);
$im->fill(50,50,$red);
binmode STDOUT;
print $im->png;
前面是定义颜色,中间是画图,最後是印出来
但是我执行後,电脑逼逼叫一下(windows工作环境)
然後出现以下乱码:
http://ppt.cc/%28@R,
在linux下没逼逼叫,但是还是一样结果是乱码
http://ppt.cc/Yg,d
我想说先把cpan里面的范例先弄懂,结果连结果都没出来
我如果把後面两行改成
open file,">test.png";
binmode file ;
print file $im->gd->png;
close file ;
这是我参考
#19nlNl8y板友大大的方法
结果出现
Can't call method "png" without a package or object reference
另外
http://linuxgazette.net/issue83/padala.html
我照里面的范本打,也是逼逼叫,一样出现乱码
但是把网址里的最後一行
print $myimage->png;换成上面的4行去执行,是可以的
所以我想说cpan里的范本应该也可以,但是就是出现
Can't call method "png" without a package or object reference
到底怎麽样show出图,或是存图起来?
--
--
▂▂ ▂▂▂
▂▄▅▅▄▆█ _█◣
◢ (●) ◣/\\
丫 │◥  ̄◤
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.116.215.116
※ 编辑: sqrt1089 来自: 140.116.215.116 (10/18 13:29)
1F:→ sqrt1089:自我回答...print file $im->gd->png;把gd删了就可以。谢 10/18 13:55
2F:→ audreytang:perl 03.p > test.png 10/18 15:43
3F:→ audreytang:或用 print file $im->png; 亦可 10/18 15:44