<?php
/*for($i=0;$i< 5;$i++){
$rand .= dechex(rand(1,15));
}*/
 $img = imagecreatetruecolor(80,20);
 $bg = imagecolorallocate($img,0,0,0);
 $te = imagecolorallocate($img,255,255,255);
imagestring($img,5,rand(5,40),0,"aaa",$te); //第一个是字体然后 X Yimageline($img,rand(1,80),rand(1,20),rand(1,80),rand(1,20),$te);header("Content-type: image/jpeg");
imagejpeg($img);
?>上面的for循环 本想是循环16进制的5位数
需要把他注掉的原因是 因为如果不注掉下面的图片显示不出来
奇怪我也没用$rand呀 为什么不行
我在imagestring里面我是随便写了一个字符串"aaa" 换成$rand 图片就成小×了。

解决方案 »

  1.   

    不可能呀我把for注释删掉  我的图片就×了
    你们那不是这样的吗?
      

  2.   

    不会吧 我把FOR 注释删掉 图片就成×了
      

  3.   

    for($i=0;$i< 5;$i++){
    $rand .= dechex(rand(1,15));
    }
     $img = imagecreatetruecolor(80,20);
     $bg = imagecolorallocate($img,0,0,0);
     $te = imagecolorallocate($img,255,255,255);
    imagestring($img,5,rand(5,40),0, $rand,$te);  //第一个是字体然后 X Yimageline($img,rand(1,80),rand(1,20),rand(1,80),rand(1,20),$te);header("Content-type: image/jpeg");
    imagejpeg($img);
    肯定是没有问题的
      

  4.   

    经测试,我机器上也存在这个问题
    解决办法:header("Content-type: image/jpeg");上一行加上 ob_clean();
      

  5.   


    牛B 谢谢搞定了 可以解释下 ob_clean()这方法吗?
      

  6.   

    估计是for的循环体里面有输出,这个很奇怪 dechex?rand? 因为header之前是不能有任何输出的,所以用ob_clean()把之前的所有输出清除掉更详细介绍可以翻手册