[BUGFIX] Image CE rendering does not scale images 56/26556/6
authorThomas Blaß <thomas@blass-net.de>
Tue, 24 Dec 2013 11:33:46 +0000 (12:33 +0100)
committerBenjamin Mack <benni@typo3.org>
Wed, 15 Jan 2014 17:09:40 +0000 (18:09 +0100)
When rendering images with CssStyledContent while using the features
maxW and equalHeight at the same time, the rendering needs to pre-
calculate the target sizes. Doing this the GifBuilder is used to
determine the width and height of the file while still relying on the
being a locally reachable path. Since the introduction of FAL uids will
be present at that point and therefore this calcuation will fail.

This change extracts the width and height of the image from the
according file object which not only fixes the the mentioned issue but
will be way more performant since the values doe not need to be
derived from the filesystem.

Resolves: #45086
Releases: 6.2
Change-Id: Icb03d337bb84851a5c905a45c4941fc9d9539033
Reviewed-on: https://review.typo3.org/26556
Reviewed-by: Wouter Wolters
Reviewed-by: Frans Saris
Reviewed-by: Thomas Blaß
Tested-by: Thomas Blaß
Reviewed-by: Benjamin Mack
Tested-by: Benjamin Mack
typo3/sysext/css_styled_content/Classes/Controller/CssStyledContentController.php

index 2f3baa3..871a9c9 100644 (file)
@@ -570,20 +570,24 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                // EqualHeight
                $equalHeight = intval($this->cObj->stdWrap($conf['equalH'], $conf['equalH.']));
                if ($equalHeight) {
-                       // Initiate gifbuilder object in order to get dimensions AND calculate the imageWidth's
-                       $gifCreator = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
-                       $gifCreator->init();
                        $relations_cols = array();
                        // contains the individual width of all images after scaling to $equalHeight
                        $imgWidths = array();
                        for ($a = 0; $a < $imgCount; $a++) {
                                $imgKey = $a + $imgStart;
-                               $imgInfo = $gifCreator->getImageDimensions($imgPath . $imgs[$imgKey]);
+
+                               /** @var $file \TYPO3\CMS\Core\Resource\File */
+                               if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($imgs[$imgKey])) {
+                                       $file = $this->getResourceFactory()->getFileObject((int)$imgs[$imgKey]);
+                               } else {
+                                       $file = $this->getResourceFactory()->getFileObjectFromCombinedIdentifier($imgPath . $imgs[$imgKey]);
+                               }
+
                                // relationship between the original height and the wished height
-                               $rel = $imgInfo[1] / $equalHeight;
+                               $rel = $file->getProperty('height') / $equalHeight;
                                // if relations is zero, then the addition of this value is omitted as the image is not expected to display because of some error.
                                if ($rel) {
-                                       $imgWidths[$a] = $imgInfo[0] / $rel;
+                                       $imgWidths[$a] = $file->getProperty('width') / $rel;
                                        // counts the total width of the row with the new height taken into consideration.
                                        $relations_cols[(int)floor($a / $colCount)] += $imgWidths[$a];
                                }
@@ -1219,4 +1223,12 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                }
        }
 
+       /**
+        * Get the ResourceFactory
+        *
+        * @return \TYPO3\CMS\Core\Resource\ResourceFactory
+        */
+       protected function getResourceFactory() {
+               return \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
+       }
 }