private function addTextLayer($image, $text, $position)
 {
     $coordinates = Image::getTextCoordinates($position);
     $textLayer = $this->manager->canvas($image->width(), $image->height(), [0, 0, 0, 0]);
     for ($x = -2; $x <= 2; $x++) {
         for ($y = -2; $y <= 2; $y++) {
             $textLayer->text($text, $coordinates['x'] + $x, $coordinates['y'] + $y, function ($font) {
                 $font->file(Image::getFontFile());
                 $font->size(85);
                 $font->color('#000');
                 // Glow color
                 $font->align('center');
                 $font->valign('top');
             });
         }
     }
     //$textLayer->blur(10);
     $textLayer->text($text, $coordinates['x'], $coordinates['y'], function ($font) {
         $font->file(Image::getFontFile());
         $font->size(85);
         $font->color('#FFF');
         // Text color
         $font->align('center');
         $font->valign('top');
     });
     return $textLayer;
 }
Ejemplo n.º 2
0
 private function createEmptyImage(int $width, int $height) : Image
 {
     $sId = sprintf('%s-%s', $width, $height);
     if (!isset($this->cachedSizes[$sId])) {
         $this->cachedSizes[$sId] = $this->imageManager->canvas($width, $height, 'ffffff');
     }
     return clone $this->cachedSizes[$sId];
 }
Ejemplo n.º 3
0
 public function setUp()
 {
     $manager = new ImageManager();
     $this->jpg = $manager->canvas(100, 100)->encode('jpg');
     $this->png = $manager->canvas(100, 100)->encode('png');
     $this->gif = $manager->canvas(100, 100)->encode('gif');
     $this->manipulator = new Encode();
 }
Ejemplo n.º 4
0
 /**
  * Create captcha image
  *
  * @param string $config
  * @return ImageManager->response
  */
 public function create($config = 'default')
 {
     $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds');
     $this->fonts = $this->files->files(__DIR__ . '/../assets/fonts');
     $this->fonts = array_values($this->fonts);
     //reset fonts array index
     $this->configure($config);
     $this->text = $this->generate();
     session_start();
     $_SESSION['text'] = $this->text;
     $this->canvas = $this->imageManager->canvas($this->width, $this->height, $this->bgColor);
     if ($this->bgImage) {
         $this->image = $this->imageManager->make($this->background())->resize($this->width, $this->height);
         $this->canvas->insert($this->image);
     } else {
         $this->image = $this->canvas;
     }
     if ($this->contrast != 0) {
         $this->image->contrast($this->contrast);
     }
     $this->text();
     $this->lines();
     if ($this->sharpen) {
         $this->image->sharpen($this->sharpen);
     }
     if ($this->invert) {
         $this->image->invert($this->invert);
     }
     if ($this->blur) {
         $this->image->blur($this->blur);
     }
     return $this->image->response('png', $this->quality);
 }
Ejemplo n.º 5
0
 /**
  * Get the image resource being used.
  *
  * @return \Intervention\Image\Image
  */
 public function getImage()
 {
     if ($this->image) {
         return $this->image;
     }
     return $this->image = $this->imageManager->canvas(350, 150, '888888');
 }
Ejemplo n.º 6
0
 /**
  * @return \Intervention\Image\Image
  */
 public function generate()
 {
     $words = $this->break_words($this->name);
     $this->name_initials = strtoupper(trim($words[0][0])) . strtoupper(trim($words[count($words) - 1][0]));
     $colors = ["#F44336", "#3F51B5", "#3F51B5", "#03A9F4", "#009688", "#4CAF50", "#CDDC39", "#FBC02D", "#FF9800", "#795548"];
     $char_index = ord($this->name_initials[0]) + ord($this->name_initials[1]);
     $color_index = $char_index % 10;
     $color = $colors[$color_index];
     if ($this->shape == 'circle') {
         $canvas = $this->image_manager->canvas(480, 480);
         $canvas->circle(480, 240, 240, function ($draw) use($color) {
             $draw->background($color);
         });
     } else {
         $canvas = $this->image_manager->canvas(480, 480, $color);
     }
     $canvas->text($this->name_initials, 240, 240, function ($font) {
         $font->file(__DIR__ . '/fonts/mononoki-Bold.ttf');
         $font->size(240);
         $font->color('#ffffff');
         $font->valign('middle');
         $font->align('center');
     });
     return $canvas->resize($this->size, $this->size);
 }
Ejemplo n.º 7
0
 /**
  * @param string $config
  * @return ImageManager->response
  */
 public function create($config = 'default')
 {
     $this->backgrounds = $this->files->files(base_path() . "/resources/assets/Captcha/backgrounds");
     $this->fonts = $this->files->files(base_path() . "/resources/assets/Captcha/fonts");
     $this->configure($config);
     $this->text = $this->generate();
     $this->canvas = $this->imageManager->canvas($this->width, $this->height, $this->bgColor);
     if ($this->bgImage) {
         $this->image = $this->imageManager->make($this->background())->resize($this->width, $this->height);
         $this->canvas->insert($this->image);
     } else {
         $this->image = $this->canvas;
     }
     if ($this->contrast != 0) {
         $this->image->contrast($this->contrast);
     }
     $this->text();
     $this->lines();
     if ($this->sharpen) {
         $this->image->sharpen($this->sharpen);
     }
     if ($this->invert) {
         $this->image->invert($this->invert);
     }
     if ($this->blur) {
         $this->image->blur($this->blur);
     }
     return $this->image->response('png', $this->quality);
 }
Ejemplo n.º 8
0
 /**
  * @return \Intervention\Image\Image
  */
 public function generate()
 {
     $words = $this->break_words($this->name);
     $number_of_word = 1;
     foreach ($words as $word) {
         if ($number_of_word > 2) {
             break;
         }
         $this->name_initials .= strtoupper(trim($word[0]));
         $number_of_word++;
     }
     $colors = ["#1abc9c", "#2ecc71", "#3498db", "#9b59b6", "#34495e", "#16a085", "#27ae60", "#2980b9", "#8e44ad", "#2c3e50", "#f1c40f", "#e67e22", "#e74c3c", "#ecf0f1", "#95a5a6", "#f39c12", "#d35400", "#c0392b", "#bdc3c7", "#7f8c8d"];
     $char_index = ord($this->name_initials[0]) - 64;
     $color_index = $char_index % 20;
     $color = $colors[$color_index];
     if ($this->shape == 'circle') {
         $canvas = $this->image_manager->canvas(480, 480);
         $canvas->circle(480, 240, 240, function ($draw) use($color) {
             $draw->background($color);
         });
     } else {
         $canvas = $this->image_manager->canvas(480, 480, $color);
     }
     $canvas->text($this->name_initials, 240, 240, function ($font) {
         $font->file(__DIR__ . '/fonts/arial-bold.ttf');
         $font->size(220);
         $font->color('#ffffff');
         $font->valign('middle');
         $font->align('center');
     });
     return $canvas->resize($this->size, $this->size);
 }
Ejemplo n.º 9
0
 public function generateImagesFromLetter(ImageStrategy $strategy, string $letter) : ImageCollection
 {
     $palette = $this->colorsService->getRandomPalette();
     $bgColor = $palette->getBackground();
     $textColor = $palette->getForeground();
     $size = max($strategy->getSizes());
     $fontSize = (int) $size * 0.8;
     $img = $this->imageManager->canvas($size, $size, $bgColor->getHexCode());
     $char = strtoupper($strategy->getLetter());
     $fontPath = $this->fontPath;
     $img->text($char, (int) $size / 2, (int) $size / 2, function (Font $font) use($fontSize, $textColor, $fontPath) {
         $font->file($fontPath);
         $font->size($fontSize);
         $font->color($textColor->getHexCode());
         $font->align('center');
         $font->valign('center');
     });
     return $this->generateImagesFromSource($strategy, $img);
 }
Ejemplo n.º 10
0
 /**
  * @param int    $width
  * @param int    $height
  * @param int    $padding
  * @param string $background
  * @return Image
  */
 public function draw($width, $height, $padding = 0, $background = '#fff')
 {
     $canvas = $this->imageManager->canvas($width, $height, $background);
     $maxX = $this->getHighestX();
     $maxY = $this->getHighestY();
     $stepX = ($width - 2 * $padding) / ($maxX + 1);
     $stepY = ($height - 2 * $padding) / ($maxY + 1);
     foreach ($this->buckets as $bucket) {
         $x = $bucket->getX() * $stepX + $padding;
         $y = $bucket->getY() * $stepY + $padding;
         if ($bucket instanceof Text) {
             $text = $bucket->getText();
             $canvas->text($text, $x, $y, function (Font $font) use($bucket) {
                 $font->file($bucket->getFont());
                 $font->size($bucket->getFontSize());
                 $font->color($bucket->getColor());
                 $font->align('center');
                 $font->valign('center');
                 $font->angle($bucket->getRotation());
             });
         }
     }
     return $canvas->response('png', 100);
 }
Ejemplo n.º 11
0
 /**
  * Creates an empty image canvas
  *
  * @param integer $width
  * @param integer $height
  * @param mixed $background
  * @return \Intervention\Image\Image 
  * @static 
  */
 public static function canvas($width, $height, $background = null)
 {
     return \Intervention\Image\ImageManager::canvas($width, $height, $background);
 }
Ejemplo n.º 12
0
 /**
  * Return a placeholder image containing the provided text.
  *
  * @param string $text
  *
  * @return string
  */
 private static function placeholder($text)
 {
     $image_manager = new ImageManager(['driver' => 'imagick']);
     $image = $image_manager->canvas(640, 480, '#efefef');
     $image->text($text, 320, 240 - 70 * substr_count($text, "\n"), function ($font) {
         $font->file(base_path('vendor/webfontkit/open-sans/fonts/opensans-regular.woff'));
         $font->size(60);
         $font->color('#cbcbcb');
         $font->align('center');
         $font->valign('center');
     });
     $image_data = (string) $image->encode('gif');
     return 'data:image/gif;base64,' . base64_encode($image_data);
 }
Ejemplo n.º 13
0
 protected function buildAvatar()
 {
     $x = $this->width / 2;
     $y = $this->height / 2;
     $manager = new ImageManager(array('driver' => config('avatar.driver')));
     $this->image = $manager->canvas($this->width, $this->height);
     $this->createShape();
     $this->chooseFont();
     $this->image->text($this->initials, $x, $y, function (AbstractFont $font) {
         $font->file($this->font);
         $font->size($this->fontSize);
         $font->color($this->foreground);
         $font->align('center');
         $font->valign('middle');
     });
 }
Ejemplo n.º 14
0
 /**
  * Table Image
  */
 public function table_img($photo, $filename)
 {
     $manager = new ImageManager();
     $dir = Config::get('system_settings.tables_upload_path');
     if (!is_dir($dir)) {
         mkdir($dir);
     }
     $background = $manager->canvas(256, 256);
     $image = $manager->make($photo)->resize(intval(Config::get('images.table_image_size')), NULL, function ($constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     });
     $background->insert($image, 'center');
     $background->save($dir . $filename);
     return $image;
 }
Ejemplo n.º 15
0
 /**
  * Save and resize the image
  * @param  ImageManager $resizer
  * @return void
  */
 public function handle(ImageManager $resizer, Filesystem $filesystem)
 {
     $filesystem->makeDirectory($this->path, 0755, true, true);
     $image = $resizer->make($this->source);
     $image->backup();
     $this->sizes->each(function ($dims, $size) use($resizer, $image) {
         $size = !$size || $size === 'default' ? '' : "{$size}_";
         $dest = "{$this->path}/{$size}{$this->filename}";
         if ($dims->width && !$dims->height) {
             $image->resize($dims->width, null, function ($constraint) {
                 $constraint->aspectRatio();
                 $constraint->upsize();
             })->save($dest, $this->quality);
         } else {
             if ($dims->height && !$dims->width) {
                 $image->resize(null, $dims->height, function ($constraint) {
                     $constraint->aspectRatio();
                     $constraint->upsize();
                 })->save($dest, $this->quality);
             } else {
                 if ($dims->padding) {
                     $image->resize($dims->width - $dims->padding, $dims->height - $dims->padding, function ($constraint) {
                         $constraint->aspectRatio();
                         $constraint->upsize();
                     });
                 } else {
                     $image->fit($dims->width, $dims->height, function ($constraint) {
                         $constraint->aspectRatio();
                         $constraint->upsize();
                     });
                 }
                 $resizer->canvas($dims->width, $dims->height, $dims->bg)->insert($image, 'center')->save($dest, $this->quality);
             }
         }
         $image->reset();
     });
     $image->destroy();
 }