I\'m trying to process a directory of JPEG images (roughly 600+, ranging from 50k to 500k) using PHP: GD to resize and save the images but I\'ve hit a bit of a snag quite ea
Simply use ini_set(); and set the memory_limit to whatever size you want.
It's possible that one or more of your images actually inflate to 16M in raw memory. One way to check is to open it in Photoshop or Irfanview and check the color space and pixel dimensions.
It doesn't take much to reach 16M, for example, consider a "lowly" 6 megapixel camera. It creates a 3072 pixel by 2048 pixel image. At a byte per color (RGB) the raw size is:
3072 x 2048 x 3 = 18,874,368
So, you might want to increase the memory according to the largest images you expect to process. But you have to consider their raw size.
ini_set('memory_limit', '64M');
problem solved
In some cases you simply cannot anticipate the highest memory allocation that will be needed by the images you are about to process. To prevent a crash, you may include following commands before and after your loop :
register_shutdown_function ('my_function');
$mem_limit = ini_get ('memory_limit');
ini_set ('display_errors', false);
ini_set ('memory_limit', '400M'); // some high value
(...your process...)
ini_set ('memory_limit',$mem_limit);
And place within the function "my_function ()" the code that will handle the crash.