Exemplo n.º 1
0
 $bg = Request::get('bg', '333333', false);
 $color = Request::get('color', 'FFFFAA', false);
 $padding = Request::get('padding', 0);
 $width = Request::get('width', 100) + $padding * 2;
 $height = Request::get('height', 30) + $padding * 2;
 $size = Request::get('size', 16);
 $length = Request::get('length', 7);
 $font = Request::get('font', 'special-elite-regular.ttf', false);
 $text = substr(str_shuffle($str), 0, $length);
 Session::set(Guardian::$captcha, $text);
 if ($bg !== 'false' && ($bg = Converter::HEX2RGB($bg))) {
     $bg = array($bg['r'], $bg['g'], $bg['b'], $bg['a']);
 } else {
     $bg = $bg !== 'false' ? array(51, 51, 51, 1) : array(0, 0, 0, 0);
 }
 if ($color = Converter::HEX2RGB($color)) {
     $color = array($color['r'], $color['g'], $color['b'], $color['a']);
 } else {
     $color = array(255, 255, 170, 1);
 }
 $image = imagecreatetruecolor($width, $height);
 $font = strpos($font, '/') === false ? ASSET . DS . '__captcha' . DS . $font : ROOT . DS . File::path($font);
 imagefill($image, 0, 0, 0x7fff0000);
 imagealphablending($image, true);
 imagesavealpha($image, true);
 $bg = imagecolorallocatealpha($image, $bg[0], $bg[1], $bg[2], 127 - $bg[3] * 127);
 $color = imagecolorallocatealpha($image, $color[0], $color[1], $color[2], 127 - $color[3] * 127);
 imagefilledrectangle($image, 0, 0, $width, $height, $bg);
 // center the image text ...
 $xi = imagesx($image);
 $yi = imagesy($image);
Exemplo n.º 2
0
 /**
  * ====================================================================
  *  COMBINE MULTIPLE IMAGE FILE(S) INTO A SINGLE IMAGE (SPRITE)
  * ====================================================================
  *
  * -- CODE: -----------------------------------------------------------
  *
  *    Image::take(array(
  *        'icon-1.png',
  *        'icon-2.png',
  *        'icon-3.png'
  *    ))->merge(0, 'vertical')->saveAs('sprites.png');
  *
  * --------------------------------------------------------------------
  *
  */
 public static function merge($gap = 0, $orientation = 'vertical', $bg = false, $alpha_for_hex = 1)
 {
     $bucket = array();
     $width = 0;
     $height = 0;
     $max_width = array();
     $max_height = array();
     $orientation = strtolower($orientation);
     self::$open = (array) self::$open;
     foreach (self::getInfo() as $info) {
         $bucket[] = array('width' => $info['width'], 'height' => $info['height']);
         $max_width[] = $info['width'];
         $max_height[] = $info['height'];
         $width += $info['width'] + $gap;
         $height += $info['height'] + $gap;
     }
     if (!$bg) {
         $bg = array(0, 0, 0, 0);
         // transparent
     }
     if (is_array($bg)) {
         if (count($bg) === 3) {
             $bg[] = 1;
             // missing alpha channel
         }
         list($r, $g, $b, $a) = array_values($bg);
     } else {
         $bg = (string) $bg;
         if ($bg[0] === '#' && ($color = Converter::HEX2RGB($bg))) {
             $r = $color['r'];
             $g = $color['g'];
             $b = $color['b'];
             $a = $alpha_for_hex;
         } else {
             if ($color = Converter::RGB($bg)) {
                 $r = $color['r'];
                 $g = $color['g'];
                 $b = $color['b'];
                 $a = $color['a'];
             }
         }
     }
     $a = 127 - $a * 127;
     if ($orientation[0] === 'v') {
         $pallete = imagecreatetruecolor(max($max_width), $height - $gap);
     } else {
         $pallete = imagecreatetruecolor($width - $gap, max($max_height));
     }
     $bg = imagecolorallocatealpha($pallete, $r, $g, $b, $a);
     imagefill($pallete, 0, 0, $bg);
     imagealphablending($pallete, true);
     imagesavealpha($pallete, true);
     $start_width_from = 0;
     $start_height_from = 0;
     for ($i = 0, $count = count(self::$open); $i < $count; ++$i) {
         self::gen(self::$open[$i]);
         imagealphablending(self::$GD, false);
         imagesavealpha(self::$GD, true);
         imagecopyresampled($pallete, self::$GD, $start_width_from, $start_height_from, 0, 0, $bucket[$i]['width'], $bucket[$i]['height'], $bucket[$i]['width'], $bucket[$i]['height']);
         $start_width_from += $orientation[0] === 'h' ? $bucket[$i]['width'] + $gap : 0;
         $start_height_from += $orientation[0] === 'v' ? $bucket[$i]['height'] + $gap : 0;
     }
     self::twin($pallete, 'png');
     return new static();
 }