Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should GD need so much memory when resizing?

Tags:

php

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.

like image 949
benpalmer Avatar asked Sep 10 '10 11:09

benpalmer


1 Answers

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.

like image 128
Mad Scientist Avatar answered Oct 02 '22 23:10

Mad Scientist