Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unknown image measures in ImageSizeViewHelper #2026

Open
DavidBruchmann opened this issue Mar 9, 2023 · 3 comments · May be fixed by #2027
Open

unknown image measures in ImageSizeViewHelper #2026

DavidBruchmann opened this issue Mar 9, 2023 · 3 comments · May be fixed by #2027

Comments

@DavidBruchmann
Copy link

DavidBruchmann commented Mar 9, 2023

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
Copy link
Author

Here is the patch

ImageSizeViewHelper.zip

@georgringer
Copy link
Owner

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

@DavidBruchmann
Copy link
Author

Sure, patch #2027 is waiting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants