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?
views:
88answers:
1The 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).