public static function output($type=0, $length=4, $sessionName = 'VerificationCode'){ self::$length = $length ? $length : 1; self::$sessionName = $sessionName; self::$type = $type ? $type : mt_rand() % 4 +1; if (self::$type == 4) { self::$fontSize[0] =16; self::$fontSize[1] =18; self::$fontFace = self::$fontChinese[mt_rand() % count(self::$fontChinese)]; } else{ self::$fontSize[0] =20; self::$fontSize[1] =24; self::$fontFace = self::$font[mt_rand() % count(self::$font)]; } self::$width = (int)(24 * self::$length+tan(deg2rad(30))*24); //self::$width = 110; self::$height = 40; if (strlen(self::$code)==0) self::createCode(); //生成码值 self::$image=imagecreatetruecolor(self::$width,self::$height); //两种生成模式的图片 if (self::$type == 4) { self::createImage1(); } else{ if (mt_rand()%2) { self::createImage1(); } else self::createImage2(); } //加入干扰象素; for($i=0; $i<self::$width; $i++){ $randcolor = ImageColorallocate(self::$image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)); imagesetpixel(self::$image, mt_rand()%self::$width , mt_rand()%self::$height , $randcolor); } header("Content-type: image/png"); imagepng(self::$image); imagedestroy(self::$image); /*echo self::$type; echo ' - '; echo self::$code;*/ }