Issue Bug Closed

#106142Exception when you try to render a processed image with viewhelper <f:image>

Florian Rival 02/10/25, 15:09 updated 02/11/25, 12:16

Description

If you try to render an image which have been processed, an exception is displayed :

> Unable to render image tag in “tt_content:139”: Resolved file object type TYPO3\CMS\Core\Resource\ProcessedFile for /fileadmin/_processed_/6/2/csm_session-my-image_0fc684693d.jpg must be File or FileReference.

This works :

<f:image src="/fileadmin/my-image.jpg" alt="" maxWidth="800"/>

That doesn’t work :

<f:image src="/fileadmin/_processed_/6/2/csm_session-my-image_0fc684693d.jpg" alt="" maxWidth="800"/>

The problem is in file extbase/Classes/Service/ImageService.php

The code checks if the image is an instance of File :

$resolvedImage = $this->getImageFromSourceString($src, $treatIdAsReference);

if ($resolvedImage instanceof File || $resolvedImage instanceof FileReference) {
   return $resolvedImage;
}

But in case of processed image, this is an instance of ProcessedFile so the test should be with AbstractFile instead of File :

$resolvedImage = $this->getImageFromSourceString($src, $treatIdAsReference);

if ($resolvedImage instanceof AbstractFile || $resolvedImage instanceof FileReference) {
   return $resolvedImage;
}

Reviews 1