ImageManager.php 1012 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Service\File\Manager;
  4. use ApiPlatform\Api\IriConverterInterface;
  5. use App\Entity\Core\File;
  6. use App\Service\File\Exception\FileNotFoundException;
  7. use App\Service\File\Factory\ImageFactory;
  8. use App\Service\ServiceIterator\StorageIterator;
  9. class ImageManager extends AbstractFileManager
  10. {
  11. public function __construct(
  12. IriConverterInterface $iriConverter,
  13. StorageIterator $storageIterator,
  14. private ImageFactory $imageFactory
  15. )
  16. {
  17. parent::__construct($iriConverter, $storageIterator);
  18. }
  19. /**
  20. * Lit le fichier et retourne son contenu
  21. *
  22. * @param File $file
  23. * @return string
  24. * @throws FileNotFoundException
  25. */
  26. public function read(File $file, int $height = 0, int $width = 0): string
  27. {
  28. $storage = $this->getStorageFor($file);
  29. $binary = $storage->getBinaryImage($file);
  30. return $this->imageFactory->create($binary, $file->getConfig(), $height, $width);
  31. }
  32. }