for($i=0;$i<4;$i++){  $rand.=dechex(rand(1,15));}
//设置图像大小
$im=imagecreatetruecolor(100,30);
//设置颜色
$bg=imagecolorallocate($im,0,0,0);
$te=imagecolorallocate($im,255,255,255);
//把字符串写在图像上面
imagestring($im,rand(3,6),rand(3,70),rand(0,16),$rand,$te);
//输出图像
header("Content-type: image/jpeg");
imagejpeg($im);
?>为何图片显示一个红叉。。
gd库已经打开

解决方案 »

  1.   


    error_reporting(E_ALL ^ E_NOTICE);开头加上这一行,,或者先预定义变量再使用
      

  2.   

    $rand没有初始化,造成输出
    Notice: Undefined variable: rand在文件头上加上 $rand = '';就可以了
      

  3.   

    注释掉 header("Content-type: image/jpeg");
    就能看到原因
      

  4.   

    session_start();
     $rand='';
    for($i=0;$i<4;$i++){  $rand.=dechex(rand(1,15));}//设置图像大小
    $_SESSION[check]=$rand;
    $im=imagecreatetruecolor(100,30);
    //设置颜色
    $bg=imagecolorallocate($im,0,0,0);
    $te=imagecolorallocate($im,255,255,255);
    //把字符串写在图像上面
    imagestring($im,rand(3,6),rand(3,70),rand(0,16),$rand,$te);
    //输出图像
    header("Content-type: image/jpeg");
    imagejpeg($im);
    这样加入session又不能显示了,何解。。
      

  5.   

    如何我吧$_SESSION[check]=$rand;注释掉就有用,为什么会这样啊
      

  6.   

    $_SESSION['check']=$rand;    //加上引号或者页面加上:error_reporting(E_ALL & ~E_NOTICE); 
      

  7.   

    本帖最后由 xuzuning 于 2012-08-17 19:40:44 编辑