免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1874 | 回复: 2
打印 上一主题 下一主题

GD画图出错,求教 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-03 11:06 |只看该作者 |倒序浏览
我用GD画图的时候,能不能读取一个文件中的数据然后画图呢,我这样做了,但是出现internal server error错误。
如果不从文件中读取,而是把数据放在程序中,就没有问题,请大家指教


下面是我从文件中读取数据然后画图的程序:


#!d:/perl/bin/perl


use GD;


print "Content-type: image/png\n\n";


my $file="test.txt";


sub min{
        my @a=@_;
        my $s=pop @a;;
        @a=map {$_-$s} @a;
        return @a;



}


my @new;

open(FILE,$file) or die;
while(my $line=<FILE>){
        chomp $line;
        my @num=split /,/$dd[4];
        push @new,@num;



}


close(FILE);

@new=sort {$a<=>$b} @new;


my $cha=$new[-1]-$new[0];


my $bei=$cha/700;
#my $bei=int ($cha/600);
my $size=$cha/$bei;


# create a new image 图片大小按压缩之后X1.1倍
my $im = new GD::Image($size*1.1+100,100);


# allocate some colors
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);


# make the background transparent and interlaced
$im->transparent($white);
$im->interlaced('true');


my $one=0;
my $two=20;
my $three=10;
my $four=5;


open(FILE,$file) or die;
while(my $line=<FILE>){
        chomp $line;
        my @dd=split /\t/,$line;
        my $name=$dd[1];
        my @num=split /,/,$dd[4];
        @num=sort {$a<=>$b} @num;


        @num= &min(@num,$new[0]);  ##传递参数给子程序的时候,会将所有参数存为一个数组 @_


        for(my $i=0;$i<@num;){


$im->rectangle($num[$i]/$bei+100,$one,$num[$i+1]/$bei+100,$two,
$black);


$im->fill($num[$i]/$bei+100+($num[$i+1]/$bei-$num[$i]/$bei)/2,$three,
$black);
                $i=$i+2;
        }
        for(my $i=1;$i<@num-1;){


$im->line($num[$i]/$bei+100,$three,$num[$i+1]/$bei+100,$three,
$black);
                $i=$i+2;
        }


        $im->string(gdLargeFont,0,$four,$name,$black);


        # make sure we are writing to a binary stream
        binmode STDOUT;


        # Convert the image to PNG and print it on standard output
        print $im->png;


        $one=$one+40;
        $two=$two+40;
        $three=$three+40;
        $four=$four+35;



}


close(FILE);

[ 本帖最后由 duziteng 于 2009-11-3 11:13 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-11-03 16:48 |只看该作者
原帖由 duziteng 于 2009-11-3 11:06 发表
我用GD画图的时候,能不能读取一个文件中的数据然后画图呢,我这样做了,但是出现internal server error错误。
如果不从文件中读取,而是把数据放在程序中,就没有问题,请大家指教


下面是我从文件中读 ...


你加上use strict 和/或 use warnings再观察apache的error_log.

论坛徽章:
0
3 [报告]
发表于 2009-11-03 23:30 |只看该作者
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP