/** * @param ThumbnailRepository $thumbnailRepository * @param ResourceType $sourceFileResourceType * @param string $sourceFileDir * @param string $sourceFileName * @param int $requestedWidth * @param int $requestedHeight */ public function __construct(ThumbnailRepository $thumbnailRepository, ResourceType $sourceFileResourceType, $sourceFileDir, $sourceFileName, $requestedWidth, $requestedHeight) { parent::__construct($sourceFileResourceType, $sourceFileDir, $sourceFileName, $requestedWidth, $requestedHeight); $this->thumbnailRepository = $thumbnailRepository; $this->adjustDimensions(); $this->backend = $thumbnailRepository->getThumbnailBackend(); $width = $this->adjustedSizeInfo['width']; $height = $this->adjustedSizeInfo['height']; $this->resizedImageFileName = ResizedImage::createFilename($sourceFileName, $width, $height); }
/** * Renames all resized images created for given file * * @param ResourceType $sourceFileResourceType * @param string $sourceFilePath * @param string $originalSourceFileName * @param string $newSourceFileName */ public function renameResizedImages(ResourceType $sourceFileResourceType, $sourceFilePath, $originalSourceFileName, $newSourceFileName) { $resizedImagesDir = Path::combine($sourceFileResourceType->getDirectory(), $sourceFilePath, ResizedImage::DIR); $resizedImagesPath = Path::combine($resizedImagesDir, $originalSourceFileName); $newResizedImagesPath = Path::combine($resizedImagesDir, $newSourceFileName); $backend = $sourceFileResourceType->getBackend(); if ($backend->hasDirectory($resizedImagesPath)) { if ($backend->rename($resizedImagesPath, $newResizedImagesPath)) { $resizedImages = $backend->listContents($newResizedImagesPath); foreach ($resizedImages as $resizedImage) { if (!isset($resizedImage['path'])) { continue; } $sourceImageSize = ResizedImage::getSizeFromFilename($resizedImage['basename']); $newResizedImageFilename = ResizedImage::createFilename($newSourceFileName, $sourceImageSize['width'], $sourceImageSize['height']); $backend->rename($resizedImage['path'], Path::combine($newResizedImagesPath, $newResizedImageFilename)); } } } }