private function createEmptyImages(ImageStrategy $strategy) : ImageCollection { $collection = new ImageCollection(); array_map(function (int $size) use($collection, $strategy) { $dir = $this->touchDir($strategy->getFilesystem(), $strategy->getEntityId(), $collection->getUID(), $size); $file = sprintf('%s.png', GenerateRandomString::gen(self::GENERATE_FILENAME_LENGTH)); $strategy->getFilesystem()->write("{$dir}/{$file}", ''); $collection->attachImage((string) $size, new ImageCollectionItem("{$dir}/{$file}", sprintf("%s/%s/%s/%s", $strategy->getPublicPath(), $strategy->getEntityId(), $size, $file))); }, $strategy->getSizes()); return $collection; }
private function setImages(ImageStrategy $strategy, ImageCollection $collection) { if ($collection->hasImage($strategy->getDefaultSize())) { $collection->attachImage('default', clone $collection->getImage((string) $strategy->getDefaultSize())); } else { $collection->attachImage('default', clone $collection->getImage(max($strategy->getSizes()))); } $strategy->getEntity()->setImages($collection); }
public function generateImagesFromSource(ImageStrategy $strategy, ImageLayer $source) : ImageCollection { $collection = new ImageCollection(); array_map(function (int $size) use($source, $collection, $strategy) { $ratio = array_filter(explode(':', $strategy->getRatio()), function ($input) { return is_numeric($input); }); if (count($ratio) !== 2) { throw new InvalidRatioException(sprintf('Invalid ratio `%s`', $strategy->getRatio())); } $width = $size; $height = $size / (int) $ratio[0] * (int) $ratio[1]; $image = clone $source; $image->resize($width, $height); $dir = $this->touchDir($strategy->getFilesystem(), $strategy->getEntityId(), $collection->getUID(), $size); $file = sprintf('%s.png', GenerateRandomString::gen(self::GENERATE_FILENAME_LENGTH)); $strategy->getFilesystem()->write("{$dir}/{$file}", $image->encode('png')); $collection->attachImage((string) $size, new Image("{$dir}/{$file}", sprintf("%s/%s/%s/%s/%s", $strategy->getPublicPath(), $strategy->getEntityId(), $collection->getUID(), $size, $file))); }, $strategy->getSizes()); return $collection; }
public function setImages(ImageCollection $images) { $this->image = $images->toJSON(); return $this; }