为了账号安全,请及时绑定邮箱和手机立即绑定

提示,图像存在错误,无法显示,以下是我的代码

<?php
      
    session_start();
    
    $image=imagecreatetruecolor(200,60);//创建一个宽100,高30的图片
   $bgcolor=imagecolorallocate($image,255,255,255);
    imagefill($image,0,0,$bgcolor);//将白色$bgcolor填充底图,从左上角填充到右上角
    
 /*   
     for($i=0;$i<4;$i++) //增加数字
     {             
     $fontsize=6;//定义数字的字体大小
     $fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));//在这张图片资源上申请一个颜色,就是数字的颜色
     $fontcontent=rand(0,9);//数字的内容,随机生成0-9
      $x=($i*100/4)+rand(5,10);//坐标来标识随机数字写在哪里
      $y=rand(5,10);
     imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);//在$image的图像资源上,画随机数字
    }
*/
  $fontface='FZYTK.TTF';
  $strdb=array('慕','课','网','赞');
  $captch_code='';
   for($i=0;$i<4;$i++)//增加字母和数字
{
      $fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
      $cn=$strdb[$i];
      $captcha_code.=$cn;
      imagettftext($image,mt_rand(20,24),mt_rand(-60,60),(40*$i+20),mt_rand(30,35),$fontcolor,$fontface,$cn);

     
    }
  $_SESSION['authcode']=$captch_code;



  for($i=0;$i<200;$i++)//增加200个以内的随机点
{
     $pointcolor=imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));//生成点的颜色
     imagesetpixel($image,rand(1,199),rand(1,59),$pointcolor);//
}
for($i=0;$i<3;$i++)//增加线
{
     $linecolor=imagecolorallocate($image,rand(80,220),rand(80,220),rand(80,220));
     imageline($image,rand(1,199),rand(1,59),rand(1,199),rand(1,59),$linecolor);
}
     header('content-type: image/png');//表明输出内容的格式
    imagepng($image);//输出&image
//end
  imagedestroy($image);//销毁&image
?>

正在回答

2 回答

谢谢你,我已经改了这个,可是图片乱码哎http://img1.sycdn.imooc.com//574ffa4600013f1105640292.jpg

0 回复 有任何疑惑可以回复我~

第一个循环里面那个变量$captcha_code比前面申明的变量$captch_code多了一个a

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

提示,图像存在错误,无法显示,以下是我的代码

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信