8.0精度丢失 v2.8.4 */ for ($i = 0; $i < $count; $i++) { $font_color = imagecolorallocate($img, mt_rand(0, 100), mt_rand(0, 50), mt_rand(0, 255)); imagettftext( $img, $font_size, floor(mt_rand(0, 20) - mt_rand(0, 25)), floor($img_w * $i / 4) + floor(mt_rand(0, 15)), floor(mt_rand($img_h / 2, $img_h)), $font_color, realpath($fontfile), $code[$i] ); } /*背景干扰点点*/ for ($i = 0; $i < 300; $i++) { $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagesetpixel($img, mt_rand(0, $img_w), mt_rand(0, $img_h), $color); } /*干扰线条*/ for ($i = 0; $i < 5; $i++) { $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imageline($img, mt_rand(0, $img_w), 0, mt_rand(0, $img_h), $img_h, $color); imagesetpixel($img, mt_rand(0, $img_w), mt_rand(0, $img_h), $color); } // 因为有些浏览器,访问的content-type会是文本型,所以我们需要设置成图片的格式类型 header("content-type:image/png"); imagepng($img); //建立png函数 imagedestroy($image);