Should GD need so much memory when resizing?
I have a resize script i made in PHP that uses GD (my VPS doesn't have imagemagick installed) to resize an 开发者_开发知识库image, I have recently started getting memory errors so i have increased the memory_limit up to 50Mb and still get memory error.
The image I am trying to resize is only 2Mb, is this correct for PHP image stuff, something sounds a bit wrong to me.
To resize the image GD has to work on the uncompressed image, which is significantly larger than 2MB, I assume. Imagemagick needs to store the entire image data (pixels * bit_depth) and quite some more for the actual work in memory.
50 Megabytes is not much for working with images. For example, Drupal warns you if you have less than 96MB memory limit, if you have the image resizing, etc.. enabled. For reasonably sized images 64MB are enough in my experience, but if you put full size images from a digital camera you'll run into problems with that memory limit.
On my shared/cloud hosting (2.7£/month) I still did not see any warning/error when resizing images. I set the limit to 200MB (sometimes users need to upload very large images). As Fabian said, I guess 50 is too low.
精彩评论