news icon indicating copy to clipboard operation
news copied to clipboard

unknown image measures in ImageSizeViewHelper

Open DavidBruchmann opened this issue 2 years ago • 3 comments

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

  • TYPO3 version(s): 11.5.24
  • news version: 10.0.3
  • Is your TYPO3 installation set up with Composer (Composer Mode): yes
  • OS: Linux

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 avatar Mar 09 '23 19:03 DavidBruchmann

Here is the patch

ImageSizeViewHelper.zip

DavidBruchmann avatar Mar 09 '23 19:03 DavidBruchmann

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

georgringer avatar Mar 10 '23 07:03 georgringer

Sure, patch #2027 is waiting

DavidBruchmann avatar Mar 18 '23 22:03 DavidBruchmann