开发者

memory_limit=80M. what is the maximum image size for imagecreateformjpeg()?

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 fact开发者_高级运维or?


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).


Probably your script uses more memory than the just the image itself. Trying debugging your memory consumption.

One quick-and-dirty way is to utilize memory_get_usage and memory_get_usage memory_get_peak_usage on certain points in your code and especially in a custom error_handler and shutdown_function. This can let you know what exact operations causes the memory exhaustion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜