From f273fff1749825fe624dce5958fe338dec01247e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Bla=C3=9F?= <thomas@blass-net.de>
Date: Tue, 24 Dec 2013 12:33:46 +0100
Subject: [PATCH] [BUGFIX] Image CE rendering does not scale images
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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
---
 .../Controller/CssStyledContentController.php | 24 ++++++++++++++-----
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/typo3/sysext/css_styled_content/Classes/Controller/CssStyledContentController.php b/typo3/sysext/css_styled_content/Classes/Controller/CssStyledContentController.php
index 2f3baa3400fd..871a9c95dc52 100644
--- a/typo3/sysext/css_styled_content/Classes/Controller/CssStyledContentController.php
+++ b/typo3/sysext/css_styled_content/Classes/Controller/CssStyledContentController.php
@@ -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();
+	}
 }
-- 
GitLab