聘我网

新概念招聘3.0

PHP写验证码的问题

vote up0vote downstar

我用php写了一个验证吗。可是背景颜色始终黑色的哇,我吧我的代码贴上帮帮忙哪里改下改成绿色的背景

  function show(){
        $word=array("光棍","快乐","爱你","小树","我的","想起");
        $name=$word[rand(0,5)];
        $im=imagecreatetruecolor(62,20);
        $black=imagecolorallocate($im,rand(20,100),rand(20,100),rand(20,100));
        $white=imagecolorallocate($im,255,255,255);

        $str=iconv("gbk","utf-8",$name);
        imagettftext($im,14,1,15,17,$white,'simkai.ttf',$str);

              for($i=0;$i<200;$i++)
                    {
       $randcolor  =  ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
               imagesetpixel($im,  rand()%70  ,  rand()%30  ,  $randcolor);}
                  header("content-type: image/jpeg");
                     imagejpeg($im);
        }
 

1 个答复

vote up0vote down

使用imagefill 可以改变背景色。

int imagefill ( resource image, int x, int y, int color)

imagefill() 在 image 图像的坐标 x,y(图像左上角为 0, 0)处用 color 颜色执行区域填充(即与 x, y 点颜色相同且相邻的点都会被填充)。

链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.