Skip to content

Commit

Permalink
Don't stretch image beyond its original dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
kitzberger committed Aug 29, 2023
1 parent 51b4106 commit c865489
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Classes/DataProcessing/FilesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit c865489

Please sign in to comment.