[BUGFIX] Fallback to argument values in f:image/f:media on invalid dimensions 38/44138/8
authorClaus Due <claus@namelesscoder.net>
Sun, 18 Oct 2015 02:10:27 +0000 (04:10 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 13 Nov 2015 18:13:04 +0000 (19:13 +0100)
* Check which width/height to use; the ones from arguments or the
  ones returned after image scaling (uses original if different).
* Do not apply the "width" and "height" attributes if resolved
  dimensions are empty.

The effect is that if the ViewHelper is used with dimensions on a
site that does *NOT* support image resizing, rather than output an
invalid tag (with width/height being zero or full size of image)
it now outputs a tag where width/height is set to the (numeric part
of the) value of the width/height arguments.

Long story short: if the server can't scale images the browser can.

Change-Id: I8bcaa5954a7f71d16656b85789b6d7d63298a0d8
Resolves: #54772
Resolves: #40254
Releases: master
Reviewed-on: https://review.typo3.org/44138
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Oliver Eglseder <oliver.eglseder@in2code.de>
Tested-by: Oliver Eglseder <oliver.eglseder@in2code.de>
Reviewed-by: Steffen Müller <typo3@t3node.com>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/MediaViewHelper.php

index 73c5720..9eee065 100644 (file)
@@ -120,11 +120,26 @@ class ImageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedV
             'crop' => $crop,
         );
         $processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions);
+        $tagWidthAttribute = (int)$processedImage->getProperty('width');
+        $tagHeightAttribute = (int)$processedImage->getProperty('height');
+        $trimmedWidthAttribute = (int)trim($width, 'cm');
+        $trimmedHeightAttribute = (int)trim($height, 'cm');
+
+        if ($trimmedWidthAttribute !== $tagWidthAttribute) {
+            $tagWidthAttribute = $trimmedWidthAttribute;
+        }
+        if ($trimmedHeightAttribute !== $tagHeightAttribute) {
+            $tagHeightAttribute = $trimmedHeightAttribute;
+        }
         $imageUri = $this->imageService->getImageUri($processedImage, $absolute);
 
         $this->tag->addAttribute('src', $imageUri);
-        $this->tag->addAttribute('width', $processedImage->getProperty('width'));
-        $this->tag->addAttribute('height', $processedImage->getProperty('height'));
+        if (!empty($tagWidthAttribute)) {
+            $this->tag->addAttribute('width', $tagWidthAttribute);
+        }
+        if (!empty($tagHeightAttribute)) {
+            $this->tag->addAttribute('height', $tagHeightAttribute);
+        }
 
         $alt = $image->getProperty('alternative');
         $title = $image->getProperty('title');
index f967a09..7bdca6c 100644 (file)
@@ -116,11 +116,26 @@ class MediaViewHelper extends AbstractTagBasedViewHelper
         );
         $imageService = $this->getImageService();
         $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions);
+        $tagWidthAttribute = (int)$processedImage->getProperty('width');
+        $tagHeightAttribute = (int)$processedImage->getProperty('height');
+        $trimmedWidthAttribute = (int)trim($width, 'cm');
+        $trimmedHeightAttribute = (int)trim($height, 'cm');
+
+        if ($trimmedWidthAttribute !== $tagWidthAttribute) {
+            $tagWidthAttribute = $trimmedWidthAttribute;
+        }
+        if ($trimmedHeightAttribute !== $tagHeightAttribute) {
+            $tagHeightAttribute = $trimmedHeightAttribute;
+        }
         $imageUri = $imageService->getImageUri($processedImage);
 
         $this->tag->addAttribute('src', $imageUri);
-        $this->tag->addAttribute('width', $processedImage->getProperty('width'));
-        $this->tag->addAttribute('height', $processedImage->getProperty('height'));
+        if (!empty($tagWidthAttribute)) {
+            $this->tag->addAttribute('width', $tagWidthAttribute);
+        }
+        if (!empty($tagHeightAttribute)) {
+            $this->tag->addAttribute('height', $tagHeightAttribute);
+        }
 
         $alt = $image->getProperty('alternative');
         $title = $image->getProperty('title');