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

十年热恋 提交于 2021-02-08 05:04:56

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/3382098/memory-limit-80m-what-is-the-maximum-image-size-for-imagecreateformjpeg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!