예제 #1
0
 /**
  * @param array $options
  *
  * @return string
  */
 public function generate(array &$options)
 {
     $this->builder->setDistortion($options['distortion']);
     $this->builder->setMaxFrontLines($options['max_front_lines']);
     $this->builder->setMaxBehindLines($options['max_behind_lines']);
     if (isset($options['text_color']) && $options['text_color']) {
         if (count($options['text_color']) !== 3) {
             throw new \RuntimeException('text_color should be an array of r, g and b');
         }
         $color = $options['text_color'];
         $this->builder->setTextColor($color[0], $color[1], $color[2]);
     }
     if (isset($options['background_color']) && $options['background_color']) {
         if (count($options['background_color']) !== 3) {
             throw new \RuntimeException('background_color should be an array of r, g and b');
         }
         $color = $options['background_color'];
         $this->builder->setBackgroundColor($color[0], $color[1], $color[2]);
     }
     $this->builder->setInterpolation($options['interpolation']);
     $fingerprint = isset($options['fingerprint']) ? $options['fingerprint'] : null;
     $content = $this->builder->build($options['width'], $options['height'], $options['font'], $fingerprint)->getGd();
     if ($options['keep_value']) {
         $options['fingerprint'] = $this->builder->getFingerprint();
     }
     if (!$options['as_file']) {
         ob_start();
         imagejpeg($content, null, $options['quality']);
         return ob_get_clean();
     }
     return $this->imageFileHandler->saveAsFile($content);
 }
예제 #2
0
 /**
  * 生成登录页面的图形验证码
  *
  * @author young
  * @name 生成登录页面的图形验证码
  * @version 2013.11.07 young
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function captchaAction()
 {
     $builder = new CaptchaBuilder();
     $builder->setBackgroundColor(255, 255, 255);
     $builder->setTextColor(255, 0, 255);
     $builder->setPhrase(rand(100000, 999999));
     $_SESSION['phrase'] = $builder->getPhrase();
     $builder->build(150, 40);
     header('Content-type: image/jpeg');
     $this->response->setContent($builder->output(80));
     return $this->response;
 }