public static function createImage($width, $height, $lenght) { // First generate the code $code = Captcha::createCode($lenght); // Create the images $img = imagecreatetruecolor($width, $height); $bgColor = imagecolorallocate($img, 245, 245, 245); ImageFill($img, 0, 0, $bgColor); $security_number = empty($_SESSION['security_number']) ? 'error' : $_SESSION['security_number']; $image_text = $security_number; $red = rand(100, 255); $green = rand(100, 255); $blue = rand(100, 255); $text_color = imagecolorallocate($img, 255 - $red, 255 - $green, 255 - $blue); $text = imagettftext($img, 15, rand(-10, 10), rand(10, 40), rand(25, 30), $text_color, "assets/fonts/courbd.ttf", $image_text); imagejpeg($img); }
/** * 获取验证码 */ public function getCaptcha() { $now = time(); $captcha_obj = new Captcha(); //$captcha_obj->doImg(); $captcha = $captcha_obj->createCode(); $captcha_encode = $this->encryptionCaptcha($captcha, $now); Star_Cookie::set('captcha', $captcha_encode, $now + self::CAPTCHA_TIMEOUT); Star_Cookie::set('ct', $now, $now + self::CAPTCHA_TIMEOUT); return $captcha; }