From c86548957785f985a3d50e53028c65b019aa83ef Mon Sep 17 00:00:00 2001 From: Philipp Kitzberger Date: Tue, 29 Aug 2023 09:17:01 +0200 Subject: [PATCH] Don't stretch image beyond its original dimensions --- Classes/DataProcessing/FilesProcessor.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Classes/DataProcessing/FilesProcessor.php b/Classes/DataProcessing/FilesProcessor.php index 75fab3a3..8a9eb6f7 100644 --- a/Classes/DataProcessing/FilesProcessor.php +++ b/Classes/DataProcessing/FilesProcessor.php @@ -205,6 +205,8 @@ protected function processFiles(array $properties = []): ?array ); // 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) { @@ -218,8 +220,10 @@ protected function processFiles(array $properties = []): ?array $properties, [ 'fileExtension' => $formatConf['fileExtension'] ?? null, - 'width' => $targetWidth * $factor, - 'height' => $targetHeight * $factor, + // 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,