views:

88

answers:

1

i have a webhosting that gives maximum memory_limit of 80M (i.e. ini_set("memory_limit","80M");). I'm using photo upload that uses the function imagecreatefromjpeg(); When i upload large images it gives the error "Fatal error: Allowed memory size of 83886080 bytes exhausted" What maximum size (in bytes) for the image i can restrict to the users? or the memory_limit depends on some other factor?

+2  A: 

The memory size of 8388608 is 8 Megabytes, not 80. You may want to check whether you can still increase the value somewhere.

Other than that, the general rule for image manipulation is that it will take at least

image width x image height x 3 

bytes of memory to load or create an image. (One byte for red, one byte for green, one byte for blue, possibly one more for alpha transparency)

By that rule, a 640 x 480 pixel image will need at least 9.2 Megabytes of space - not including overhead and space occupied by the script itself.

It's impossible to determine a limit on the JPG file size in bytes because JPG is a compressed format with variable compression rates. You will need to go by image resolution and set a limit on that.

If you don't have that much memory available, you may want to look into more efficient methods of doing what you want, e.g. tiling (processing one part of an image at a time) or, if your provider allows it, using an external tool like ImageMagick (which consumes memory as well, but outside the PHP script's memory limit).

Pekka
Hi Pekka, Thanks for the answer and sorry I mistakenly written as 8388608 it's actually 83886080 bytes.And when i tried to upload 3200X2400 with 3.5MB, it's giving error. what max width or height or size i can restrict for uploading to prevent the error? Thanks in Advance :-)
Arun David
@Arun hard to tell! 3200x2400 image should fit fine in 80 MB - it could be that the script isn't efficiently written and is storing the whole image in multiple variables.
Pekka