diff --git a/Classes/DataProcessing/FilesProcessor.php b/Classes/DataProcessing/FilesProcessor.php index 16e6559d..8a9eb6f7 100644 --- a/Classes/DataProcessing/FilesProcessor.php +++ b/Classes/DataProcessing/FilesProcessor.php @@ -175,51 +175,61 @@ protected function processFiles(array $properties = []): ?array { $data = []; $cropVariant = $this->processorConfiguration['processingConfiguration.']['cropVariant'] ?? 'default'; + $formats = $this->processorConfiguration['processingConfiguration.']['formats.'] ?? []; + + // Legacy workaround + $autogenerateConfig = $this->processorConfiguration['processingConfiguration.']['autogenerate.'] ?? null; + if ($autogenerateConfig) { + if (($autogenerateConfig['retina2x'] ?? 0) == 1) { + $formats['urlRetina'] = [ + 'factor' => FileUtility::RETINA_RATIO, + ]; + } + if (($autogenerateConfig['lqip'] ?? 0) == 1) { + $formats['urlLqip'] = [ + 'factor' => FileUtility::LQIP_RATIO, + ]; + } + } foreach ($this->fileObjects as $key => $fileObject) { - if (isset($this->processorConfiguration['processingConfiguration.']['autogenerate.'])) { + if ($formats) { + $delayProcessing = (int)($this->processorConfiguration['processingConfiguration.']['delayProcessing'] ?? 0) === 1; + + // 1. render image as usual $file = $this->getFileUtility()->processFile( $fileObject, $properties, $cropVariant, - (int)($this->processorConfiguration['processingConfiguration.']['delayProcessing'] ?? 0) === 1 + $delayProcessing ); - $targetWidth = (int)($properties['width'] ?: $file['properties']['dimensions']['width']); - $targetHeight = (int)($properties['height'] ?: $file['properties']['dimensions']['height']); - - if (isset($this->processorConfiguration['processingConfiguration.']['autogenerate.']['retina2x']) && - (int)$this->processorConfiguration['processingConfiguration.']['autogenerate.']['retina2x'] === 1 && - ($targetWidth || $targetHeight)) { - $file['urlRetina'] = $this->getFileUtility()->processFile( - $fileObject, - array_merge( - $properties, - [ - 'width' => $targetWidth * FileUtility::RETINA_RATIO, - 'height' => $targetHeight * FileUtility::RETINA_RATIO, - ] - ), - $cropVariant, - (int)($this->processorConfiguration['processingConfiguration.']['delayProcessing'] ?? 0) === 1 - )['publicUrl']; - } - - if (isset($this->processorConfiguration['processingConfiguration.']['autogenerate.']['lqip']) && - (int)$this->processorConfiguration['processingConfiguration.']['autogenerate.']['lqip'] === 1 && - ($targetWidth || $targetHeight)) { - $file['urlLqip'] = $this->getFileUtility()->processFile( - $fileObject, - array_merge( - $properties, - [ - 'width' => $targetWidth * FileUtility::LQIP_RATIO, - 'height' => $targetHeight * FileUtility::LQIP_RATIO, - ] - ), - $cropVariant, - (int)($this->processorConfiguration['processingConfiguration.']['delayProcessing'] ?? 0) === 1 - )['publicUrl']; + // 2. render additional formats + $originalWidth = $fileObject->getProperty('width'); + $originalHeight = $fileObject->getProperty('height'); + $targetWidth = (int)($properties['width'] ?? $file['properties']['dimensions']['width']); + $targetHeight = (int)($properties['height'] ?? $file['properties']['dimensions']['height']); + if ($targetWidth || $targetHeight) { + foreach ($formats as $formatKey => $formatConf) { + $formatKey = rtrim($formatKey, '.'); + $factor = (float)($formatConf['factor'] ?? 1.0); + + $file[$formatKey] = $this->getFileUtility()->processFile( + $fileObject, + array_merge( + $properties, + [ + 'fileExtension' => $formatConf['fileExtension'] ?? null, + // multiply width/height by factor, + // but don't stretch image beyond its original dimensions! + 'width' => min($targetWidth * $factor, $originalWidth), + 'height' => min($targetHeight * $factor, $originalHeight), + ] + ), + $cropVariant, + $delayProcessing + )['publicUrl']; + } } $data[] = $file; diff --git a/Classes/DataProcessing/GalleryProcessor.php b/Classes/DataProcessing/GalleryProcessor.php index 15d62f10..1f614bdd 100644 --- a/Classes/DataProcessing/GalleryProcessor.php +++ b/Classes/DataProcessing/GalleryProcessor.php @@ -178,6 +178,23 @@ private function getCroppedDimensionalPropertyFromProcessedFile(array $processed */ protected function prepareGalleryData() { + $formats = $this->processorConfiguration['formats.'] ?? []; + + // Legacy workaround + $autogenerateConfig = $this->processorConfiguration['autogenerate.'] ?? null; + if ($autogenerateConfig) { + if (($autogenerateConfig['retina2x'] ?? 0) == 1) { + $formats['urlRetina'] = [ + 'factor' => FileUtility::RETINA_RATIO, + ]; + } + if (($autogenerateConfig['lqip'] ?? 0) == 1) { + $formats['urlLqip'] = [ + 'factor' => FileUtility::LQIP_RATIO, + ]; + } + } + for ($row = 1; $row <= $this->galleryData['count']['rows']; $row++) { for ($column = 1; $column <= $this->galleryData['count']['columns']; $column++) { $fileKey = (($row - 1) * $this->galleryData['count']['columns']) + $column - 1; @@ -186,31 +203,36 @@ protected function prepareGalleryData() if ($fileObj) { if ($fileObj['properties']['type'] === 'image') { $image = $this->getImageService()->getImage((string)$fileObj['properties']['fileReferenceUid'], null, true); - $fileObj = $this->getFileUtility()->processFile($image, $this->mediaDimensions[$fileKey] ?? []); - if (isset($this->processorConfiguration['autogenerate.']['retina2x'], - $fileObj['properties']['dimensions']['width']) && - (int)$this->processorConfiguration['autogenerate.']['retina2x'] === 1) { - $fileObj['urlRetina'] = $this->getFileUtility()->processFile( + // 1. render image as usual + $fileObj = $this->getFileUtility()->processFile( + $image, + array_merge( + ['fileExtension' => $this->processorConfiguration['fileExtension'] ?? null], + $this->mediaDimensions[$fileKey] ?? [] + ) + ); + + // 2. render additional formats + $originalWidth = $image->getProperty('width'); + $originalHeight = $image->getProperty('height'); + $targetWidth = $fileObj['properties']['dimensions']['width']; + $targetHeight = $fileObj['properties']['dimensions']['height']; + foreach ($formats ?? [] as $formatKey => $formatConf) { + $formatKey = rtrim($formatKey, '.'); + $factor = (float)($formatConf['factor'] ?? 1.0); + + $fileObj[$formatKey] = $this->getFileUtility()->processFile( $image, [ - 'width' => $fileObj['properties']['dimensions']['width'] * FileUtility::RETINA_RATIO, - 'height' => $fileObj['properties']['dimensions']['height'] * FileUtility::RETINA_RATIO, + 'fileExtension' => $formatConf['fileExtension'] ?? null, + // multiply width/height by factor, + // but don't stretch image beyond its original dimensions! + 'width' => min($targetWidth * $factor, $originalWidth), + 'height' => min($targetHeight * $factor, $originalHeight), ] )['publicUrl']; } - - if (isset($this->processorConfiguration['autogenerate.']['lqip'], - $fileObj['properties']['dimensions']['width']) && - (int)$this->processorConfiguration['autogenerate.']['lqip'] === 1) { - $fileObj['urlLqip'] = $this->getFileUtility()->processFile( - $image, - [ - 'width' => $fileObj['properties']['dimensions']['width'] * FileUtility::LQIP_RATIO, - 'height' => $fileObj['properties']['dimensions']['height'] * FileUtility::LQIP_RATIO, - ] - )['publicUrl']; - } } $this->galleryData['rows'][$row]['columns'][$column] = $fileObj;