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
K3.1 feature-hmvc: Fatal error, when upload 8 images #2310 #2401
Conversation
{ | ||
list($width, $height) = getimagesize($file['tmp_name']); | ||
|
||
// Getting the image pixels, then multiply them by 4 (4 bytes per pixel at CMYK), then adding the “tweak factor” as the memory_limit function is not so precise, and adding 1MByte more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually RGB images are often stored by using 4 bytes as it makes the processing faster (and a few graphics cards use that format having one unused byte).
There is a way to reduce memory usage:
imagepng($image);
imagedestroy($image);
Having destroy will free the allocated memory after each step.
Memory usage for images is according to some sources:
imagecreatetruecolor = width*height*5 bytes.
imagepng = width*height*4 bytes.
Remember that GD needs to allocate memory for both the original and resized image.
We could also allocate more memory for the operation:
ini_set('memory_limit', '1024M'); // Calculate memory usage instead of having hard coded value...
This seems to be the most commonly used calculation method:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had followed that : http://alvarotrigo.com/blog/allocate-memory-on-the-fly-with-php-for-image-resizing/, it's seem it's the same that here : http://www.dotsamazing.com/en/labs/phpmemorylimit
An other way is to use imagemagick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the really correct one would be to take the current memory usage and add memory usage from the largest image + resized version of it -- maybe with the same 1MB margin.
$memoryNeeded = current usage + 1MB + width_height_6 + resized width_height_6
list($width, $height) = getimagesize($file['tmp_name']); | ||
|
||
// Getting the image pixels, then multiply them by 4 (4 bytes per pixel at CMYK), then adding the “tweak factor” as the memory_limit function is not so precise, and adding 1MByte more | ||
$memory_needed .= floor(($width * $height * 4 * 1.5 + 1048576) / 1048576); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, this doesn't work as it concatenates strings together. I think we need to take MAX() from all the incoming memory usages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to put a destroy in /components/com_kunena/site/lib/kunena.upload.class.php when resizing image is finished, this file is deprecated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot remove the file without breaking older templates. The class will be removed in 4.0.
I'am closing this one because it's repalced by #2414 |
No description provided.