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

Placeholder for large images #71

Open
lochmueller opened this issue Jun 13, 2023 · 3 comments
Open

Placeholder for large images #71

lochmueller opened this issue Jun 13, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@lochmueller
Copy link

Hey everyone,

currently, the placeholder service just stores the result of the URI in the target file without checking for errors. If there are errors/problems in the placeholder service the result is JSON and there is an error message. I got this error, because I use filefill for large images and the images are to large for https://via.placeholder.com/ as result, there is a "jpg" file in the filesystem with a JSON error in it. Bad for further processing like EXT:webp and regular content elements.

As result I add this code after this line https://github.com/IchHabRecht/filefill/blob/main/Classes/Resource/Handler/PlaceholderResource.php#L82 to reduce the file size, if the file size is the problem. I don't check the max file dimension or different errors of the service. This code just handle my usecase.

            if ($response->getHeaderLine('Content-Type') === 'application/json') {
                $result = \json_decode($content);
                if (isset($result->error) && $result->error === 'Requested image size is too large') {

                    $fileData = $fileObject->getProperties();
                    $fileData['identifier'] = $fileObject->getIdentifier();
                    $fileData['name'] = $fileObject->getName();

                    // half size
                    $fileData['width'] = floor($fileData['width'] / 2);
                    $fileData['height'] = floor($fileData['height'] / 2);

                    $fileObjectResized = new File($fileData, $fileObject->getStorage());

                    return $this->getFile($fileData['identifier'], $filePath, $fileObjectResized);
                }
            }

Perhaps PlaceholderResource.php should handle this more generall (at least throw an Exception if the result is json, so the getFile method return false).

Regards,
Tim

@IchHabRecht
Copy link
Owner

Hi @lochmueller,

Are you talking about the file size or the file dimensions? Can you give me some example that will return an error?

@lochmueller
Copy link
Author

Hey @IchHabRecht
sorry... please replace all "size" with "dimension" :-) Here is an example: https://via.placeholder.com/3840x2160.jpg
Regards,
Tim

@IchHabRecht
Copy link
Owner

Hi @lochmueller

Thanks for your feedback. I will work on this issue as soon as I find some spare time.

@IchHabRecht IchHabRecht added the bug Something isn't working label Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants