/** * @param IFile $image * @param IImageFormat[] $imageFormats if is NULL all image formats will be removed */ public function removeFormatedImages(IFile $image, array $imageFormats = []) { if (empty($imageFormats)) { $imageFormats = $this->imageFormatProvider->findAll(); } foreach ($imageFormats as $imageFormat) { $path = $this->getPath($image, $imageFormat); if (file_exists($path)) { @unlink($path); } $dir = dirname($path); if (file_exists($dir) && $this->isDirEmpty($dir)) { rmdir($dir); } } }
/** * @param string $imageName * @param string $imageFormatName * @throws BadRequestException */ public function __invoke($imageName, $imageFormatName) { $image = $this->imageProvider->findOneByName($imageName); if (!$image) { throw new BadRequestException('Image not found.', 404); } $imageFormat = $this->imageFormatProvider->findOneByName($imageFormatName); if (!$imageFormat) { throw new BadRequestException('Image format not found.', 404); } $originalImagePath = $this->storage->getPath($image); if (!file_exists($originalImagePath)) { \Tracy\Debugger::log(new \Nette\InvalidStateException('File not found in the storage.')); throw new BadRequestException('Image not found.', 404); } $path = $this->storage->getPath($image, $imageFormat); if (!file_exists($path)) { $this->storage->createFormatedImage($image, $imageFormat); } Image::fromFile($path)->send(); }