sitegeist / sms-responsive-images

This TYPO3 extension provides ViewHelpers and configuration to render valid responsive images based on TYPO3's image cropping tool.
GNU General Public License v2.0
34 stars 18 forks source link

[TASK] Check processed placeholder to prevent large inline images #97

Closed Atomschinken closed 2 years ago

NamelessCoder commented 2 years ago

Thanks for getting this started, @Atomschinken!

I tested your solution but found an issue - though not related to your changes, it means the usage of sha1 makes the solution brittle (if hash is not yet created, a an exception is shown with "hash must be a string"). There is however a different solution:

        $processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions);
        if ($processedImage->usesOriginalFile()) {
            $inline = false;
        }

I verified this by forcing the processed image to "use the original" in \TYPO3\CMS\Core\Resource\Processing\LocalImageProcessor::processTask by forcing the logic to enter the first condition and trigger:

            if ($result === null) {
                $task->setExecuted(true);
                $task->getTargetFile()->setUsesOriginalFile();

$result would be null if the image scaling logic internally failed to resize the image for any reason (image subsystem not configured, image format not scalable, etc.)

Checking if $processedImage->usesOriginalFile() should solve the problem we have and seems to be a pretty solid solution. I don't think we would need to start looking at the size etc. of the original file to only set $inline = false in case it's actually a big image - it is probably best (and simplest and more predictable) just to always disable $inline in case the image couldn't be processed.

Atomschinken commented 2 years ago

Just added it to the pull requests. Looks good to me and works as expected.

Thank you @NamelessCoder for this solution 👍