Project

General

Profile

Actions

Bug #106142

closed

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

Added by Florian Rival about 1 month ago. Updated about 1 month ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
Start date:
2025-02-10
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
8.2
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

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;
}
Actions #1

Updated by Gerrit Code Review about 1 month ago

  • Status changed from New to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/88141

Actions #2

Updated by Florian Rival about 1 month ago

The use case is this one, I have an thumbnail field in page properties which is indexed in solr like this :

index_thumbnail_stringS = FILES
index_thumbnail_stringS {
    references {
        table = pages
        uid.data = field:uid
        fieldName = tx_arcprojet_thumbnail
    }
    maxItems = 1
    renderObj = TEXT
    renderObj {
        typolink {
            parameter.stdWrap {
                cObject = IMG_RESOURCE
                cObject {
                    file.import.data = file:current:uid
                    file.treatIdAsReference = 1
                    file.height = 400c
                    file.width = 400
                }
            }
            returnLast = url
            forceAbsoluteUrl = 0
        }
        stdWrap.wrap = |
    }
}

Due to the rendering with the object IMG_RESOURCE, the file is processed and the URL that I get is the processed URL.

This use case worked with older TYPO3 version, but perhaps it is a bad practice to store processed images and the rendering must be only done at runtime.

Actions #3

Updated by Mathias Brodala about 1 month ago

  • Status changed from Under Review to Closed
Actions #4

Updated by Garvin Hicking about 1 month ago

Thanks for the extra info. The associated patch contained some further discussion which I'm quoting here:

Hm. I wonder if better you should/could transport not
the URL but the file identifier back to typoscript and
fluid, then you could do any kind if pre/reprocessing
based on that UID. 
Or pass the identifier additionally to the TS rendered
image for this additional reprocessing...?

Mathias also mentioned this would probably not be the best choice to allow re-processing an processed image which is why we closed this issue. Please feel free to come to the Slack channel to discuss some options that would be more suitable to prevent needing reprocessing like this.

Actions

Also available in: Atom PDF