Welcome Guest, Not a member yet? Register   Sign In
Memory problem
#1

[eluser]steelaz[/eluser]
I'm working on custom gallery application and have a problem with memory usage.

My controller uploads and resizes uploaded image. On my local setup, I can upload 4 Mb image, resize it and profiler shows up to 3 Mb memory usage. When I try the same image on staging website, I get an error:

"Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 17152 bytes) in /path/system/libraries/Image_lib.php on line 1157"

So controller runs out of memory on resizing image, specifically on this line 17152:

Code:
return imagecreatefromjpeg($path);

If I try smaller image (i.e. 0.5 Mb) everything works fine and profiler shows up to 3 Mb usage on both local and staging setup.

Any idea why this is happening? Could this be a problem with hosting provider?
#2

[eluser]thdls55[/eluser]
You will have to modify the value of the memory_limit PHP parameter.

Depending on your hosting environment, you may have to put something like
Code:
php_value memory_limit 16M
in your htaccess, or
Code:
ini_set('memory_limit', '16M');
into your code.
#3

[eluser]steelaz[/eluser]
Thanks, my memory limit was already at 32 Mb as you can see from the error message, I was just wondering why resizing 4 Mb images takes that much memory. Turns out, internally it is converted to bitmap. I am lucky application will be running on dedicated server, because I had to increase memory limit to 128 Mb. Anyone knows a good alternative for resizing pictures that doesn't use that much memory?
#4

[eluser]rogierb[/eluser]
From the looks of things you are using GD to resize. GD unpacks a jpg to its uncompressed state and then starts working on it. This takes a huge amount of memory, depending on compression ratio.
ImageMagick is rumoured to use a lot less memory.
#5

[eluser]steelaz[/eluser]
Yes, I'm using GD2. Any idea how ImageMagic compares to GD quality wise?
#6

[eluser]rogierb[/eluser]
Imagemagick has at least the same quality and some say even better. It is slower then GD especially for BMP (who uses that anyway) but it wont run out of memory. In general, I would go for ImageMagick over GD.
#7

[eluser]steelaz[/eluser]
Thanks Rogier, great info.




Theme © iAndrew 2016 - Forum software by © MyBB