diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php index d65d8d8216a4ebd43b0e9aabf0cd20da0391f0a5..45c7027ce51660999412c4dc5faa3c408d99f081 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php @@ -13,6 +13,8 @@ namespace TYPO3\CMS\Fluid\ViewHelpers; * * The TYPO3 project - inspiring people to share! */ + +use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection; use TYPO3\CMS\Core\Resource\FileInterface; use TYPO3\CMS\Core\Resource\FileReference; use TYPO3\CMS\Core\Resource\Rendering\RendererRegistry; @@ -70,6 +72,7 @@ class MediaViewHelper extends AbstractTagBasedViewHelper $this->registerArgument('additionalConfig', 'string', 'This array can hold additional configuration that is passed though to the Renderer object', false, []); $this->registerArgument('width', 'string', 'This can be a numeric value representing the fixed width of in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.'); $this->registerArgument('height', 'string', 'This can be a numeric value representing the fixed height in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.'); + $this->registerArgument('cropVariant', 'string', 'select a cropping variant, in case multiple croppings have been specified or stored in FileReference', false, 'default'); } /** @@ -116,11 +119,13 @@ class MediaViewHelper extends AbstractTagBasedViewHelper */ protected function renderImage(FileInterface $image, $width, $height) { - $crop = $image instanceof FileReference ? $image->getProperty('crop') : null; + $cropVariant = $this->arguments['cropVariant'] ?: 'default'; + $cropString = $image instanceof FileReference ? $image->getProperty('crop') : ''; + $cropVariantCollection = CropVariantCollection::create((string)$cropString); $processingInstructions = [ 'width' => $width, 'height' => $height, - 'crop' => $crop, + 'crop' => $cropVariantCollection->getCropArea($cropVariant)->makeAbsoluteBasedOnFile($image), ]; $imageService = $this->getImageService(); $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions); diff --git a/typo3/sysext/frontend/Classes/DataProcessing/GalleryProcessor.php b/typo3/sysext/frontend/Classes/DataProcessing/GalleryProcessor.php index 5edae4d7e514e843258de735c1ec49267ef019cf..24a99883330653487eb648b965b34b9872571f91 100644 --- a/typo3/sysext/frontend/Classes/DataProcessing/GalleryProcessor.php +++ b/typo3/sysext/frontend/Classes/DataProcessing/GalleryProcessor.php @@ -14,6 +14,7 @@ namespace TYPO3\CMS\Frontend\DataProcessing; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection; use TYPO3\CMS\Core\Resource\FileInterface; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; @@ -202,6 +203,11 @@ class GalleryProcessor implements DataProcessorInterface */ protected $borderPadding; + /** + * @var string + */ + protected $cropVariant = 'default'; + /** * The (filtered) media files to be used in the gallery * @@ -261,6 +267,7 @@ class GalleryProcessor implements DataProcessorInterface $this->borderEnabled = (bool)$this->getConfigurationValue('borderEnabled', 'imageborder'); $this->borderWidth = (int)$this->getConfigurationValue('borderWidth'); $this->borderPadding = (int)$this->getConfigurationValue('borderPadding'); + $this->cropVariant = (int)$this->getConfigurationValue('cropVariant') ?: 'default'; $this->determineGalleryPosition(); $this->determineMaximumGalleryWidth(); @@ -424,7 +431,7 @@ class GalleryProcessor implements DataProcessorInterface // Recalculate gallery width $this->galleryData['width'] = floor($maximumRowWidth / $mediaScalingCorrection); - // User entered a predefined width + // User entered a predefined width } elseif ($this->equalMediaWidth) { $mediaScalingCorrection = 1; @@ -448,10 +455,9 @@ class GalleryProcessor implements DataProcessorInterface // Recalculate gallery width $this->galleryData['width'] = floor($totalRowWidth / $mediaScalingCorrection); - // Automatic setting of width and height + // Automatic setting of width and height } else { $maxMediaWidth = (int)($galleryWidthMinusBorderAndSpacing / $this->galleryData['count']['columns']); - foreach ($this->fileObjects as $key => $fileObject) { $mediaWidth = min($maxMediaWidth, $this->getCroppedDimensionalProperty($fileObject, 'width')); $mediaHeight = floor( @@ -471,6 +477,7 @@ class GalleryProcessor implements DataProcessorInterface * * @param FileInterface $fileObject * @param string $dimensionalProperty 'width' or 'height' + * * @return int */ protected function getCroppedDimensionalProperty(FileInterface $fileObject, $dimensionalProperty) @@ -478,8 +485,10 @@ class GalleryProcessor implements DataProcessorInterface if (!$fileObject->hasProperty('crop') || empty($fileObject->getProperty('crop'))) { return $fileObject->getProperty($dimensionalProperty); } - $croppingConfiguration = json_decode($fileObject->getProperty('crop'), true); - return (int)$croppingConfiguration[$dimensionalProperty]; + + $croppingConfiguration = $fileObject->getProperty('crop'); + $cropVariantCollection = CropVariantCollection::create((string)$croppingConfiguration); + return (int) $cropVariantCollection->getCropArea($this->cropVariant)->makeAbsoluteBasedOnFile($fileObject)->asArray()[$dimensionalProperty]; } /**