/** * Create a blank image with of given dimensions and fill it with $bgColor. * * @param int $width Width of the new image. * @param int $height Height of the new image. * @param string $bgColor Background color. Following formats are acceptable * - "fff" * - "ffffff" * - array(255,255,255) * @param int $alpha Alpha transparency. * * @return \Webiny\Component\Image\ImageInterface */ public function create($width, $height, $bgColor = null, $alpha = 100) { $size = new Box($width, $height); $palette = new \Imagine\Image\Palette\RGB(); $color = $palette->color($bgColor, $alpha); return new Image($this->instance->create($size, $color)); }
/** * @param $text * @param $width * @param $height * @param string $fontSize * @param string $color * @param string $backgroundColor * @return $this */ public function createPlaceholder($text, $width, $height, $fontSize = '20', $color = '000', $backgroundColor = 'ddd') { $this->metaData = null; $this->imageSource = null; $this->imageWidth = $width; $this->imageHeight = $height; if ($this->imageFormat === null) { $this->imageFormat = 'jpg'; } if ($this->font === null) { $this->setFontFile('Public/fonts/fraym/arial.ttf'); } $bgBox = new \Imagine\Image\Box($width, $height); $imgColor = new \Imagine\Image\Palette\RGB(); $img = $this->imagine->create($bgBox, $imgColor->color($backgroundColor)); $descriptionBoxImg = new \Imagine\Gd\Font(realpath($this->font), $fontSize, $imgColor->color($color)); $descriptionBoxImg = $descriptionBoxImg->box($text, 0)->getWidth(); // set the point to start drawing text, depending on parent image width $descriptionPositionCenter = ceil(($img->getSize()->getWidth() - $descriptionBoxImg) / 2); if ($descriptionPositionCenter < 0) { $descriptionPositionCenter = 0; } $img->draw()->text($text, new \Imagine\Gd\Font(realpath($this->font), $fontSize, $imgColor->color($color)), new \Imagine\Image\Point($descriptionPositionCenter, $img->getSize()->getHeight() / 2 - $fontSize / 2), 0); $this->image = $img; return $this; }
/** * Режим замощения * @return \Imagine\Image\ImageInterface|static */ private function tilingMode() { $count = $this->count['x'] * $this->count['y']; $marginsX = $this->margins['x'] > 0 ? $this->count['x'] * $this->margins['x'] : 0; $marginsY = $this->margins['y'] > 0 ? $this->count['y'] * $this->margins['y'] : 0; $width = $this->count['x'] * $this->watermark['size']->getWidth() + $marginsX; $height = $this->count['y'] * $this->watermark['size']->getHeight() + $marginsY; //создаем большой слой для коллажа вотермарков $collage = $this->imageine->create(new Imagine\Image\Box($width, $height)); $point = $this->getPoint(); //вставляем в наше полотно исходное изображение $collage->paste($this->image['src'], $this->getPoint()); $x = 0; $y = 0; //делаем коллаж вотермарков for ($i = 0; $i < $count; $i++) { $collage->paste($this->watermark['src'], new Imagine\Image\Point($x, $y)); //смещаемся вправо на ширину картинки + отступ $x += $this->watermark['size']->getWidth() + $this->margins['x']; //Когда дошли до конца ряда, смещаемся по оси Y на высоту картинки и опять идем от левого края if ($x >= $width) { $y += $this->watermark['size']->getHeight() + $this->margins['y']; $x = 0; } } //делаем обрезку по ширине высоте исходного изображения return $collage->crop($point, new Imagine\Image\Box($this->image['size']->getWidth(), $this->image['size']->getHeight())); }
public static function create(BoxInterface $size, ColorInterface $color = null) { $adapter = new Imagine(); return $adapter->create($size, $color); }