您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

验证码的一个类,怎么就是不出来图片呢

2025/7/3 6:12:25发布27次查看
自己闲着没事,自定义了一个验证码生成的类,但是不知道为什么,图片就是现实不出来。还请高手指点一下。
img_width = $img_width; $this->img_height = $img_height; $this->font_size = $font_size; $this->line_count = $line_count; } //验证码生成主方法 function createcodeimg(){ $this->creategraphics(); $this->getchars(); $this->setnoiceline(); $x = rand(2,5); $arr_x_y = array(array($x,rand(1,3)),array($x+$this->font_size,rand(1,4)),array($x+2*$this->font_size,rand(1,3)),array($x+3*$this->font_size,rand(1,4))); print_r($arr_x_y); for($i = 0;$iimg, rand(180,250), rand(180,250), rand(180,250)); imagechar($this->img,$this->font_size,$arr_x_y[$i][0],$arr_x_y[$i][1],$this->arr_char[$i],$text_color); } } //创建画图板 function creategraphics(){ header(content-type: image/png); $this->img = @imagecreatetruecolor($this->img_width, $this->img_height) or die(建立图像失败); //创建图片 $background_color = imagecolorallocate($this->img, 250, 250, 250); imagefill($this->img,0,0,$background_color); $border_color = imagecolorallocate($this->img,0,0,0); //边框色 imagerectangle($this->img,0,0,$this->img_width,$this->img_height,$border_color); } //画噪音线 function setnoiceline(){ for($i = 0;$i line_count;$i ++){ $x1 = rand(3,20);//开始位置 $y1 = rand(2,$this->img_height); $x2 = rand($this->img_width-20,$this->img_width-2);//结束位置 $y2 = rand(2,$this->img_height); $line_color = imagecolorallocate($this->img, rand(180,250), rand(180,250), rand(180,250)); imageline($this->img,$x1,$y1,$x2,$y2,$line_color); } } //产生随机字符串或者加减字符 function getchars(){ $strcode = ; if(rand(0,1) == 1){//字符串类型的 验证码 for($i = 0;$i arr_char[$i] = $this->str_chars[rand(0,56)]; $strcode .= $this->arr_char[$i]; } $this->code_result = $strcode; } else{ //加减类型验证码 $first_num = rand(1,10); $second_num = 0; $result = 0; $arr_operater = array(+,-); $operater = $arr_operater[rand(0,1)]; switch ($operater){ case +: $second_num = rand(0,10); $result = $first_num + $second_num; break; case -: $second_num = rand(0,$first_num); $result = $first_num - $second_num; break; } $this->arr_char = array($first_num,$operater,$second_num,=); $this->code_result = $result; } }}$yzm = new imagecode(65,27,16,7);$yzm->createcodeimg();echo ($yzm->img_width.-----.$yzm->code_result);imagepng($yzm->img); imagedestroy($yzm->img);?>
回复讨论(解决方案) 木有人啊
注释掉 28 行的 print_r($arr_x_y);
注释掉 91 行的 echo ($yzm->img_width.-----.$yzm->code_result);
注释掉 28 行的 print_r($arr_x_y);
注释掉 91 行的 echo ($yzm->img_width.-----.$yzm->code_result);
这两行是我测试的,注释掉也不行
注释掉 28 行的 print_r($arr_x_y);
注释掉 91 行的 echo ($yzm->img_width.-----.$yzm->code_result);
无语啊,当时怎么都不行,加了这两行测试,怎么你说过之后,我删掉就又行了呢,搞不懂了
呵, 代码有时候就这么神奇, 仔细检查一下,看能不能找到原因 。
火狐为什么看不到 代码 框里的 左右滚动条
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product