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

K3.1 feature-hmvc: Fatal error, when upload 8 images #2310 #2401

Closed
wants to merge 1 commit into from

Conversation

xillibit
Copy link
Member

No description provided.

{
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
Copy link
Member

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:

http://www.dotsamazing.com/en/labs/phpmemorylimit

Copy link
Member Author

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

Copy link
Member

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

@mahagr mahagr added this to the 3.1.0 milestone Mar 23, 2014
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);
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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.

@xillibit
Copy link
Member Author

xillibit commented May 9, 2014

I'am closing this one because it's repalced by #2414

@xillibit xillibit closed this May 9, 2014
@coder4life coder4life modified the milestone: 3.1.0 May 9, 2014
@xillibit xillibit deleted the kdev-patch-8 branch August 30, 2014 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants