出来之后是这样
是颜色出错了还是根本没有文本加进去啊?打印$randval没显示~~不知道怎么出错的~~img.php<?php
$width=50;
$height=20;
header("Content-type:image/gif");
$randval=randstr(4);
$im=imagecreatetruecolor($width, $height);
$r=array(255,215,235,195,175);
$g=array(255,215,235,195,175);
$b=array(255,215,235,195,175);
$key=rand(0,4);
$backcolor=imagecolorallocate($im, $r[key], $g[key], $b[key]);$pointcolor=imagecolorallocate($im,255,170,255);
imagefill($im,0,0,$backcolor);
$stringcolor=imagecolorallocate($im,0,0,0);
for ($i=0;$i<=10;$i++)
{
$pointx=rand(2,$width-2);
$pointy=rand(2,$height-2);
imagesetpixel($im, $pointx, $pointy, $pointcolor);

}
imagestring($im,3,5,1,$randval,$stringcolor);
$imagefun='Imagegif';
$imagefun($im);
imagedestroy($im);
function randstr($len=10)
{
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$string="";
while(strlen($string)<$len)
{
$string.=substr($chars,(rand()%strlen($chars)),1);


}
return $string;
}
echo $randval;
?>