From 19ff2d0f1275e1a84e2eb48b63ebd659d0e7671d Mon Sep 17 00:00:00 2001
From: Frans Saris <franssaris@gmail.com>
Date: Sun, 19 Feb 2017 09:51:46 +0100
Subject: [PATCH] [BUGFIX] Only apply image cropping when cropping is set

Resolves: #79836
Releases: master
Change-Id: I29fb6f0f31a54b6f20c937881a8b523b844dde69
Reviewed-on: https://review.typo3.org/51749
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
---
 typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php    | 4 ++--
 typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php    | 3 ++-
 .../sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php  | 4 ++--
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php
index e5d0681ae371..c6f8f5e8aae1 100644
--- a/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php
+++ b/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php
@@ -16,7 +16,6 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
 
 use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
 use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
-use TYPO3\CMS\Core\Resource\FileReference;
 
 /**
  * Resizes a given image (if required) and renders the respective img tag
@@ -133,6 +132,7 @@ class ImageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedV
             }
             $cropVariantCollection = CropVariantCollection::create((string)$cropString);
             $cropVariant = $this->arguments['cropVariant'] ?: 'default';
+            $cropArea = $cropVariantCollection->getCropArea($cropVariant);
             $processingInstructions = [
                 'width' => $this->arguments['width'],
                 'height' => $this->arguments['height'],
@@ -140,7 +140,7 @@ class ImageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedV
                 'minHeight' => $this->arguments['minHeight'],
                 'maxWidth' => $this->arguments['maxWidth'],
                 'maxHeight' => $this->arguments['maxHeight'],
-                'crop' => $cropVariantCollection->getCropArea($cropVariant)->makeAbsoluteBasedOnFile($image),
+                'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image),
             ];
             $processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions);
             $imageUri = $this->imageService->getImageUri($processedImage, $this->arguments['absolute']);
diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php
index 45c7027ce516..6bfaaad3b3d5 100644
--- a/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php
+++ b/typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php
@@ -122,10 +122,11 @@ class MediaViewHelper extends AbstractTagBasedViewHelper
         $cropVariant = $this->arguments['cropVariant'] ?: 'default';
         $cropString = $image instanceof FileReference ? $image->getProperty('crop') : '';
         $cropVariantCollection = CropVariantCollection::create((string)$cropString);
+        $cropArea = $cropVariantCollection->getCropArea($cropVariant);
         $processingInstructions = [
             'width' => $width,
             'height' => $height,
-            'crop' => $cropVariantCollection->getCropArea($cropVariant)->makeAbsoluteBasedOnFile($image),
+            'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image),
         ];
         $imageService = $this->getImageService();
         $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions);
diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php
index b32c553da407..a95766de4d54 100644
--- a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php
+++ b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php
@@ -16,7 +16,6 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
 
 use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
 use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
-use TYPO3\CMS\Core\Resource\FileReference;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Extbase\Service\ImageService;
@@ -119,6 +118,7 @@ class ImageViewHelper extends AbstractViewHelper
 
             $cropVariantCollection = CropVariantCollection::create((string)$cropString);
             $cropVariant = $arguments['cropVariant'] ?: 'default';
+            $cropArea = $cropVariantCollection->getCropArea($cropVariant);
             $processingInstructions = [
                 'width' => $arguments['width'],
                 'height' => $arguments['height'],
@@ -126,7 +126,7 @@ class ImageViewHelper extends AbstractViewHelper
                 'minHeight' => $arguments['minHeight'],
                 'maxWidth' => $arguments['maxWidth'],
                 'maxHeight' => $arguments['maxHeight'],
-                'crop' => $cropVariantCollection->getCropArea($cropVariant)->makeAbsoluteBasedOnFile($image),
+                'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image),
             ];
 
             $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions);
-- 
GitLab