diff --git a/typo3/sysext/core/Classes/Resource/Processing/LocalCropScaleMaskHelper.php b/typo3/sysext/core/Classes/Resource/Processing/LocalCropScaleMaskHelper.php index d6b637751bb4..88cbe253aebc 100644 --- a/typo3/sysext/core/Classes/Resource/Processing/LocalCropScaleMaskHelper.php +++ b/typo3/sysext/core/Classes/Resource/Processing/LocalCropScaleMaskHelper.php @@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Resource\Processing; use TYPO3\CMS\Core\Core\Environment; +use TYPO3\CMS\Core\Imaging\GraphicalFunctions; use TYPO3\CMS\Core\Resource\FileInterface; use TYPO3\CMS\Core\Resource\ProcessedFile; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -203,6 +204,28 @@ public function processWithLocalFile(TaskInterface $task, string $originalFileNa GeneralUtility::unlink_tempfile($croppedImage); } + // If noScale option is applied, we need to reset the width and height to ensure the scaled values + // are used for the generated image tag even if the image itself is not scaled. This is needed, as + // the result is discarded due to the fact that the original image is used. + // @see https://forge.typo3.org/issues/100972 + // Note: This should only happen if no image has been generated ($result === null). + if ($result === null && ($options['noScale'] ?? false)) { + $imageOperations = GeneralUtility::makeInstance(GraphicalFunctions::class); + $configuration = $task->getConfiguration(); + $localProcessedFile = $task->getSourceFile()->getForLocalProcessing(false); + $imageDimensions = $imageOperations->getImageDimensions($localProcessedFile); + $imageScaleInfo = $imageOperations->getImageScale( + $imageDimensions, + $configuration['width'] ?? '', + $configuration['height'] ?? '', + $options + ); + $targetFile->updateProperties([ + 'width' => $imageScaleInfo[0], + 'height' => $imageScaleInfo[1], + ]); + } + return $result; }