georgringer / news

TYPO3 Extension news
GNU General Public License v2.0
260 stars 352 forks source link

unknown image measures in ImageSizeViewHelper #2026

Open DavidBruchmann opened 1 year ago

DavidBruchmann commented 1 year ago

Bug Report

Current Behavior Usually the width and the height of each image are known and the ViewHelper returns the correct value. For some weird reason the measures in my current installation are not known and therefore the ImageSizeViewHelper throws an error.

Expected behavior/output The ImageSizeViewHelper should return a value if possible, and if it's unknown it's possible to get the measures.

Environment

Possible Solution Above the switch-statement this code can be added

            if (in_array($arguments['property'], ['width', 'height'])
                && (
                    !array_key_exists(0, $imagesOnPage[$usedImage])
                    || !array_key_exists(1, $imagesOnPage[$usedImage])
                )
            ) {
                $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
                $rawFileLocation = $resourceFactory
                    ->getFileObjectFromCombinedIdentifier($usedImage)
                    ->getForLocalProcessing();
                $imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $rawFileLocation);
                $imagesOnPage[$usedImage][0] = $imageInfo->getWidth();
                $imagesOnPage[$usedImage][1] = $imageInfo->getHeight();
            }

above the class the use statements have to be added:

use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Type\File\ImageInfo;

Additional context Concerning the core I filed a patch already too about this problem on https://forge.typo3.org/issues/96529.

DavidBruchmann commented 1 year ago

Here is the patch

ImageSizeViewHelper.zip

georgringer commented 1 year ago

wanna do a proper PR? that would be a great help!

DavidBruchmann commented 1 year ago

Sure, patch #2027 is waiting