0

This question already has an answer here:

There is a content type in my website that has an image field. Some contents have images that are larger than 20MB.

I created an image_style called fp which scales and resizes the images in 800X400px it works well but when the browser displays this resized version it reports the following error

Allowed memory size of 134217728 bytes exhausted (tried to allocate 73834563 bytes) in modules/system/image.gd.inc on line 237

I know by increasing the memory_limit the problem will be solved (even though it is not recommended).

From what I know Drupal creates a distinct file of the original image for every image style, so in sites/default/files/styles/fp there is a resized version of the original image. It means when browser displays the resized image, the PHP needs no process to resize the image, it only displays another image which is the resized version. But why it displays the above error while it only needs to display an image (styled version) which its size is about 200kb ?

marked as duplicate by kenorb, Adrian Cid Almaguer, Scott Joudry, No Sssweat, Krishna Mohan Mar 16 '16 at 10:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

128M is somewhat low for a Drupal install. It may work well for front end pages, but I have found that it needs to be raised for admin pages. I do not know where you get the recommendation that anything over 128M isn't recommendation. That PHP variable is a holdover from custom PHP to prevent infinite loops from crashing a system. And remember, it is a max value. Page requests that use less will not get the full amount.

You are running into the problem because GD needs to load the image into memory to process it down to 800x400 before saving it to disk and serving it up for display. The problem isn't as much the file size, as what it will decompress to and occupy in memory. When you start doing the math on big images (multiple width x height x 4), you will see that, 128M is way too low. When the style has already been made, PHP never gets involved.

I believe the ImageMagick library will end up using the CLI convert utility, which can save PHP memory, but I don't recall the last time I actually tested this to be sure.

  • Thank you for your reply. The stackoverflow.com/questions/561066/… recommended not to set ini_set('memory_limit', '-1'); The When the style has already been made, PHP never gets involved. means PHP will not do any processing for styles images and it simply loads the file of the styled image, right? – M a m a D Oct 27 '15 at 13:13
  • I use the -1 setting on all of my dev and staging instances so I can get an accurate idea of how much memory an instance can use. Because memory usage isn't always consistent between forward facing, admin facing, and special things like image style creation. I have also done some tricks to adjust memory in certain situations (but that is beyond the scope of this, and rather complicated and localized). Yes, once an image style is made, it gets saved on disk, and servied directly by Apache/Nginx/IIS. The only exception would be an image from the private filesystem. – mpdonadio Oct 27 '15 at 14:00
  • I am still confused why this error is reported when the image file is already created and no processing is needed !!! – M a m a D Oct 27 '15 at 14:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.