Пример #1
0
 /**
  * Генерация шаблона из одного символа
  * @param resource $img
  * @param int      $width
  * @param int      $height
  * @return string
  */
 public static function generateTemplateChar($img, $width = 15, $height = 16)
 {
     if (imagesx($img) != $width || imagesy($img) != $height) {
         $img = Img::resize($img, $width, $height);
     }
     $colorIndexes = Divider::getColorsIndexTextAndBackground($img);
     $colorTextIndexes = array_flip($colorIndexes['text']);
     $line = '';
     for ($y = 0; $y < $height; $y++) {
         for ($x = 0; $x < $width; $x++) {
             if (isset($colorTextIndexes[$colorIndexes['pix'][$x][$y]])) {
                 $line .= '1';
             } else {
                 $line .= '0';
             }
         }
     }
     return $line;
 }
Пример #2
0
 /**
  * [watermark description]
  *
  * @return  mixed               On success, current object to allow function chaining. False otherwise.
  */
 public function watermark($source = 'Testing123', $size = 24, $angle = 20, $padding = 15, $color = '#ffffff', $background = 'transparent', $opacity = 0.5, $repeat = 'center')
 {
     $trans = $background == 'transparent' ? 0 : 1;
     $src_w = imagesx($this->img);
     $src_h = imagesy($this->img);
     # Check for image based watermark
     if (is_file($source) || is_resource($source)) {
         # Init stamp object
         $stamp = new Img($source);
         # Resize according to padding.
         $stamp->resize($size - 2 * $padding, $size - 2 * $padding);
     } else {
         # Disable padding on pattern stamps for easier calculation
         $pad = $repeat > 0 ? 0 : $padding;
         # Get the text image
         $words = $this->text_image($source, $size, $pad, $color, $background);
         # Init stamp object
         $stamp = new Img($words);
         # Reclaim memory
         imagedestroy($words);
     }
     # Apply rotation
     $stamp->rotate($angle, $background);
     # Apply watermark, create a pattern if specified.
     if ($repeat > 0) {
         $stamp->resize((imagesx($this->img) - $repeat * 2 * $padding) / $repeat)->expand($padding)->fill($background, $trans);
         $canvas = $this->transcanvas($src_w, $src_h);
         $w = imagesx($stamp->img);
         $h = imagesy($stamp->img);
         $x = $y = 0;
         while ($y <= $src_h) {
             while ($x <= $src_w) {
                 if (!imagecopy($canvas, $stamp->img, $x, $y, 0, 0, $w, $h)) {
                     return false;
                 }
                 $x += $w;
             }
             $x = 0;
             $y += $h;
         }
         # Merge stamp into image
         $success = $this->imagecopymergealpha($this->img, $canvas, 0, 0, 0, 0, $src_w, $src_h, $opacity * 100);
     } else {
         $w = imagesx($stamp->img);
         $h = imagesy($stamp->img);
         # Get stamp coordinates
         extract($this->croplocation($src_w, $src_h, $w, $h, $repeat, false));
         # Merge stamp into image
         $success = $this->imagecopymergealpha($this->img, $stamp->img, $src_x, $src_y, 0, 0, $w, $h, $opacity * 100);
     }
     # Grab arguments and substitute basename if an image was used.
     $args = func_get_args();
     if (is_file($args[0])) {
         $args = basename($args[0]);
     }
     # On success update filename and return current object for function chaining, false on error.
     return $success ? $this->update(__FUNCTION__, $args) : false;
 }