예제 #1
0
 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;
 }
예제 #2
0
 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);
 }
예제 #3
0
 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;
 }
예제 #4
0
 public function setImages(ImageCollection $images)
 {
     $this->image = $images->toJSON();
     return $this;
 }