+ -
当前位置:首页 → 问答吧 → gd生成图片问题

gd生成图片问题

时间:2010-09-17

来源:互联网

同样类似的代码,一个生成的图能正常显示,而另一个代码的图却不能显示!想了很久也不知道为什么!望高手解答,非常感谢!
此为自动生成验证码的代码:
<?php 
header("content-type:image/png");
$code = strtoupper(substr(md5(rand()),0,5));
$nimg=imagecreatetruecolor(200,30);
imagecolorallocate($nimg,255,255,255);
for($i=0;$i<=strlen($code);$i++){
$font=mt_rand(2,4);
$x=mt_rand(1,8);
$y=mt_rand(1,4)+30*$i/10;
$color=imagecolorallocate($nimg,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200));
//imagesetpixel($nimg, rand()%70 , rand()%30 , $color);  
imagestring($nimg,$font,$x,$y,$code[$i],$color);
}
imagepng($nimg);
imagedestroy($nimg);
?>
这个代码在页面上显示为:一个很小的交叉,查看属性为;超文本传送协议不可用,
而另外一个代码就能正常显示:
<?php 
header("content-type:image/png");
$nimg=imagecreatetruecolor(500,500);
$color=imagecolorallocate($nimg,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagefill($nimg,250,250,250);
imagerectangle($nimg,5,20,350,350,$color);
imageline($nimg,5,20,350,350,$color);
imagestring($nimg,5,250,250,'php5',$color);
imagepng($nimg);
imagedestroy($nimg);
 ?>
此显示正常!2个文件就这些代码,没其他多余的了!
望对gd2了解的人指点一二,非常感谢!

作者: fengyun520   发布时间: 2010-09-17

应该是没有指定高度吧

作者: sunbiao0526   发布时间: 2010-09-17

相关阅读 更多

热门下载

更多