Allowed memory size of 134217728 bytes exhausted in system\image.gd.inc reported for styled images 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 ?
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.