From 8a0057455a6375187573622b3f05a50b1553b188 Mon Sep 17 00:00:00 2001 From: David Bruchmann Date: Fri, 10 Mar 2023 15:43:21 +0700 Subject: [PATCH 1/5] Update ImageSizeViewHelper.php --- Classes/ViewHelpers/ImageSizeViewHelper.php | 48 +++++++++++++++------ 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/Classes/ViewHelpers/ImageSizeViewHelper.php b/Classes/ViewHelpers/ImageSizeViewHelper.php index 5e223e9a19..0ac3b04c87 100644 --- a/Classes/ViewHelpers/ImageSizeViewHelper.php +++ b/Classes/ViewHelpers/ImageSizeViewHelper.php @@ -11,6 +11,8 @@ use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Page\AssetCollector; +use TYPO3\CMS\Core\Resource\ResourceFactory; +use TYPO3\CMS\Core\Type\File\ImageInfo; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\VersionNumberUtility; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; @@ -60,20 +62,40 @@ public static function renderStatic( $assetCollector = GeneralUtility::makeInstance(AssetCollector::class); $imagesOnPage = $assetCollector->getMedia(); + + if (isset($imagesOnPage[$usedImage]) && $arguments['property'] == 'size') { + $file = Environment::getPublicPath() . '/' . ltrim(parse_url($usedImage, PHP_URL_PATH), '/'); + if (is_file($file)) { + return (int) @filesize($file); + } + } + elseif (in_array($arguments['property'], ['width', 'height'])) { + + // Get missing info if required + if (!array_key_exists(0, $imagesOnPage[$usedImage]) + || !array_key_exists(1, $imagesOnPage[$usedImage]) + ) { + $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); + $fileObject = $resourceFactory->getFileObjectFromCombinedIdentifier($usedImage); + if ($fileObject->isImage() + && $fileObject->getStorage()->getDriverType() === 'Local' + ) { + $rawFileLocation = $fileObject->getForLocalProcessing(); + $imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $rawFileLocation); + $imagesOnPage[$usedImage][0] = $imageInfo->getWidth(); + $imagesOnPage[$usedImage][1] = $imageInfo->getHeight(); + } + } - if (isset($imagesOnPage[$usedImage])) { - switch ($arguments['property']) { - case 'width': - $value = $imagesOnPage[$usedImage][0]; - break; - case 'height': - $value = $imagesOnPage[$usedImage][1]; - break; - case 'size': - $file = Environment::getPublicPath() . '/' . ltrim(parse_url($usedImage, PHP_URL_PATH), '/'); - if (is_file($file)) { - $value = @filesize($file); - } + if (isset($imagesOnPage[$usedImage])) { + switch ($arguments['property']) { + case 'width': + $value = $imagesOnPage[$usedImage][0]; + break; + case 'height': + $value = $imagesOnPage[$usedImage][1]; + break; + } } } From 0aef67e354a2c6da4f8998c38dde59fe5c7a6bed Mon Sep 17 00:00:00 2001 From: David Bruchmann Date: Fri, 10 Mar 2023 15:48:51 +0700 Subject: [PATCH 2/5] Update ImageSizeViewHelper.php --- Classes/ViewHelpers/ImageSizeViewHelper.php | 49 +++++++++++---------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/Classes/ViewHelpers/ImageSizeViewHelper.php b/Classes/ViewHelpers/ImageSizeViewHelper.php index 0ac3b04c87..eb43a4b271 100644 --- a/Classes/ViewHelpers/ImageSizeViewHelper.php +++ b/Classes/ViewHelpers/ImageSizeViewHelper.php @@ -63,38 +63,39 @@ public static function renderStatic( $assetCollector = GeneralUtility::makeInstance(AssetCollector::class); $imagesOnPage = $assetCollector->getMedia(); - if (isset($imagesOnPage[$usedImage]) && $arguments['property'] == 'size') { + if (isset($imagesOnPage[$usedImage])) { + if ($arguments['property'] == 'size') { $file = Environment::getPublicPath() . '/' . ltrim(parse_url($usedImage, PHP_URL_PATH), '/'); if (is_file($file)) { return (int) @filesize($file); } - } - elseif (in_array($arguments['property'], ['width', 'height'])) { + elseif (in_array($arguments['property'], ['width', 'height'])) { - // Get missing info if required - if (!array_key_exists(0, $imagesOnPage[$usedImage]) - || !array_key_exists(1, $imagesOnPage[$usedImage]) - ) { - $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); - $fileObject = $resourceFactory->getFileObjectFromCombinedIdentifier($usedImage); - if ($fileObject->isImage() - && $fileObject->getStorage()->getDriverType() === 'Local' + // Get missing info if required + if (!array_key_exists(0, $imagesOnPage[$usedImage]) + || !array_key_exists(1, $imagesOnPage[$usedImage]) ) { - $rawFileLocation = $fileObject->getForLocalProcessing(); - $imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $rawFileLocation); - $imagesOnPage[$usedImage][0] = $imageInfo->getWidth(); - $imagesOnPage[$usedImage][1] = $imageInfo->getHeight(); + $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); + $fileObject = $resourceFactory->getFileObjectFromCombinedIdentifier($usedImage); + if ($fileObject->isImage() + && $fileObject->getStorage()->getDriverType() === 'Local' + ) { + $rawFileLocation = $fileObject->getForLocalProcessing(); + $imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $rawFileLocation); + $imagesOnPage[$usedImage][0] = $imageInfo->getWidth(); + $imagesOnPage[$usedImage][1] = $imageInfo->getHeight(); + } } - } - if (isset($imagesOnPage[$usedImage])) { - switch ($arguments['property']) { - case 'width': - $value = $imagesOnPage[$usedImage][0]; - break; - case 'height': - $value = $imagesOnPage[$usedImage][1]; - break; + if (isset($imagesOnPage[$usedImage])) { + switch ($arguments['property']) { + case 'width': + $value = $imagesOnPage[$usedImage][0]; + break; + case 'height': + $value = $imagesOnPage[$usedImage][1]; + break; + } } } } From 72f6c2de2771b653c0d74c0322ee43f5ca09421d Mon Sep 17 00:00:00 2001 From: David Bruchmann Date: Fri, 10 Mar 2023 15:50:30 +0700 Subject: [PATCH 3/5] Update ImageSizeViewHelper.php --- Classes/ViewHelpers/ImageSizeViewHelper.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Classes/ViewHelpers/ImageSizeViewHelper.php b/Classes/ViewHelpers/ImageSizeViewHelper.php index eb43a4b271..7892d637e5 100644 --- a/Classes/ViewHelpers/ImageSizeViewHelper.php +++ b/Classes/ViewHelpers/ImageSizeViewHelper.php @@ -65,11 +65,11 @@ public static function renderStatic( if (isset($imagesOnPage[$usedImage])) { if ($arguments['property'] == 'size') { - $file = Environment::getPublicPath() . '/' . ltrim(parse_url($usedImage, PHP_URL_PATH), '/'); - if (is_file($file)) { - return (int) @filesize($file); - } - elseif (in_array($arguments['property'], ['width', 'height'])) { + $file = Environment::getPublicPath() . '/' . ltrim(parse_url($usedImage, PHP_URL_PATH), '/'); + if (is_file($file)) { + return (int) @filesize($file); + } + } elseif (in_array($arguments['property'], ['width', 'height'])) { // Get missing info if required if (!array_key_exists(0, $imagesOnPage[$usedImage]) From fb3b52d2979c416282bce517dae8e0323bb3d67b Mon Sep 17 00:00:00 2001 From: David Bruchmann Date: Fri, 10 Mar 2023 15:52:49 +0700 Subject: [PATCH 4/5] Update ImageSizeViewHelper.php --- Classes/ViewHelpers/ImageSizeViewHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/ViewHelpers/ImageSizeViewHelper.php b/Classes/ViewHelpers/ImageSizeViewHelper.php index 7892d637e5..53a82038f9 100644 --- a/Classes/ViewHelpers/ImageSizeViewHelper.php +++ b/Classes/ViewHelpers/ImageSizeViewHelper.php @@ -62,7 +62,7 @@ public static function renderStatic( $assetCollector = GeneralUtility::makeInstance(AssetCollector::class); $imagesOnPage = $assetCollector->getMedia(); - + if (isset($imagesOnPage[$usedImage])) { if ($arguments['property'] == 'size') { $file = Environment::getPublicPath() . '/' . ltrim(parse_url($usedImage, PHP_URL_PATH), '/'); From 15b6b17966cbec6c62b4f6bb7b3a77780840a106 Mon Sep 17 00:00:00 2001 From: David Bruchmann Date: Fri, 10 Mar 2023 15:55:36 +0700 Subject: [PATCH 5/5] Update ImageSizeViewHelper.php --- Classes/ViewHelpers/ImageSizeViewHelper.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Classes/ViewHelpers/ImageSizeViewHelper.php b/Classes/ViewHelpers/ImageSizeViewHelper.php index 53a82038f9..18d710de5d 100644 --- a/Classes/ViewHelpers/ImageSizeViewHelper.php +++ b/Classes/ViewHelpers/ImageSizeViewHelper.php @@ -87,15 +87,13 @@ public static function renderStatic( } } - if (isset($imagesOnPage[$usedImage])) { - switch ($arguments['property']) { - case 'width': - $value = $imagesOnPage[$usedImage][0]; - break; - case 'height': - $value = $imagesOnPage[$usedImage][1]; - break; - } + switch ($arguments['property']) { + case 'width': + $value = $imagesOnPage[$usedImage][0]; + break; + case 'height': + $value = $imagesOnPage[$usedImage][1]; + break; } } }