Hello,
After I upload a image with a dimension over 4999px X 4999px the right side of the panel is blank. I tried with different images the problem is the dimension not the file size.
It is a sever problem or a panel problem ?
kirby 2.5.5
thanks
Hello,
After I upload a image with a dimension over 4999px X 4999px the right side of the panel is blank. I tried with different images the problem is the dimension not the file size.
It is a sever problem or a panel problem ?
kirby 2.5.5
thanks
Please check your server error logs if you can find anything in there.
Does the file get uploaded despite the blank panel? Is the thumbnail for the panel created? Might be that thumb creation fails.
I tested this with an image of 5000 x 5000 px, but can’t reproduce this (image file size was 1,5mb)
this is the error_log output:
[Wed Oct 04 09:40:55 2017] [error] [client 84.226.154.70] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /home/www/web404/html/xxx/kirby/vendor/getkirby/toolkit/vendors/abeautifulsite/SimpleImage.php on line 1101, referer: https:/xxxpanel/pages/projekte/test/files
[Wed Oct 04 09:40:55 2017] [error] [client 84.226.154.70] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /home/www/web404/htmlxxx/kirby/vendor/filp/whoops/src/Whoops/Util/Misc.php on line 1, referer: https://xxx.org/panel/pages/projekte/test/files
It’s a memory error. Try giving PHP more memory.
Is the image transparent (png)? Transparency hogs memory in my experience.
What’s the memory_limit setting in your PHP.ini? Try to set it to a higher value.
@bvdputte beat me to it…
@bvdputte thank you for your answer, no is a .jpg
I ask my hosting support to change the memory_limit…
something like 75MB or more?
https://toolstud.io/photo/megapixel.php?width=5000&height=5000&compare=video&calculate=uncompressed
the server memory_limit is 128mb and can’t be changed.
if this maybe a solution?
kirby()->hook('panel.file.upload', 'resizeImage');
kirby()->hook('panel.file.replace', 'resizeImage');
function resizeImage($file) {
// set a max. dimension
$maxDimension = 2000;
try {
// check file type and dimensions
if ($file->type() == 'image' and ($file->width() > $maxDimension or $file->height() > $maxDimension)) {
// get the original file path
$originalPath = $file->dir() . '/' . $file->filename();
// create a thumb and get its path
$resizedImage = $file->resize($maxDimension, $maxDimension);
$resizedPath = $resizedImage->dir() . '/' . $resizedImage->filename();
// replace the original image with the resized one
copy($resizedPath, $originalPath);
unlink($resizedPath);
}
} catch (Exception $e) {
return response::error($e->getMessage());
}
}
No, if upload fails because of memory, the hook won’t work. It is only triggered when file is uploaded successfully.
is memory_limit 128mb little ?
I would say it’s enough, but then again, when do you have enough memory?
I’ll revert the question: aren’t 5000px wide images a bit much?
Well, I did a quick test on localhost with memory_limit set to 128mb.
Turns out, I get the same memory_size error when trying to upload such a big image. The upload itself works, but thumb shows an empty image.
So my conclusion: 128mb is maybe not little and should be sufficient for many use cases, but is not enough for images of that size, most likely due to thumb creation.
How big is the image in megabytes? In addition to ram limit, there is also a PHP limit on file upload. I take it this is also set sufficiently for the images you are using?
And I agree with @bvdputte - isn’t 5000px a little crazy?
Yes, but the file does seem to get uploaded, otherwise there wouldn’t be the empty thumb in the screenshot above. And file size does not seem to be the issue as outlined above:
But I also agree, why 5000px? Is that because client can’t produce smaller images? Or do you really have to cater for monster size screens?
One other thing you could try is to swap gd library for imagemagick, if you haven’t already and if supported on the server.
I don’t why the client have so big pictures but he is a real user using the internet to get information and send/receive emails what I would like to say he does not know with image size file formats etc
maybe for a future panel versions a warning message is helpfull
with imagemagick no error
thank you
The problem is not the panel: the PHP process that is working on the images crashes because the image is too big to be handeled according the PHP settings.
Sometimes you’ll need to “educate” your users a bit. E.g. if he wants to upload a RAW from his DSLR camera, this won’t work. Or neither will a HEIF image from his iphone for instance…