Visser Labs

Tuesday, December 9, 2008

Thumbnail Generation PHP Memory Limit NextGEN Gallery

When uploading a set of admittedly large images using NextGEN Gallery to my WordPress site I exceeded my web hosts default memory usage allocation for PHP applications. The error was:

Follow thumbnails could not created. sample.jpg (Error : Exceed Memory limit. Require : 80.65 MByte)

This issue can be resolved by increasing the memory usage allocation at a per-plugin level for PHP applications that require more grunt than others. It’s quick and easy!

  1. Open an FTP connection to your root WordPress directory
  2. Open /wp-content/plugins/nextgen-gallery/lib/gd.thumbnail.inc.php with your favourite text editor (e.g. UltraEdit, etc.)
  3. On line #168 un-comment (remove the //) from before @ini_set('memory_limit', '128M');
  4. Save and upload changes
  5. Delete image/s that failed to generate a thumbnail and re-upload using NextGEN Gallery’s standard Upload Images feature

If you find 128MB is too ‘conservative’ this can be increased again to any figure of your liking, I find 128MB appropriate for most commercial and personal usage but if you’re a HD photographer then you’re going to hit this limit very quickly… that’s it!

63 Comments »

  1. Bob
    December 18

    Michael – I have spent over a day trying to solve this issue – messing around with .htaccess, php.ini and memory limits. This simple solution solved the problem immediately. Thankyou so much!

  2. December 20

    Hey Bob, sweet to hear it helped. How easy would it be to manage PHP script memory limits at a WordPress Administrator level under Settings > Memory, that would be great! Add it to the wish list.

  3. December 20

    THANK YOU!!! I only last about 2 hours … but THANK YOU … whew … I’ll make sure to bookmark this ;)

  4. December 21

    Michael – Thanks for this solution. I’m new to the wordpress and web stuff so your simple solution to this problem really was amazing. I probably came across 20 other sites with solutions that just didn’t work for me. I’m not sure about blog etiquette, but I linked to your page from mine so that hopefully others will find you. If you look and I didn’t do it according to standards, let me know and I’ll happily fix it. :)

  5. December 21

    Hi Tommy,

    Thanks for your kind words, I’m glad it helped. Your site is having a few presentation difficulties of its own…

  6. Ajay
    December 26

    hi,
    I have question, if I have a lot of picture, and running professional blog adding pictures everyday. then am i going to hit this limit , if yes, then how to make it unlimited?

  7. December 26

    Hi Ajay,

    I don’t this issue will affect you as it only occurs at upload time, I do know there is a refresh thumbnail button within NextGEN that if you check all items may cause this issue but it’s unlikely you will encounter this scenario.

  8. September 22

    Ty sir. That worked like charm. No more thumbnail sizing issues. You are a huge time saver my friend.

  9. October 14

    Hi Michael,
    Just wanted to say thanks for the fix. Your post maybe nearly a year old but it’s just as relevant today as it was then.
    Graham.

  10. October 15

    Hey Graham, it’s an oldie but a goodie! Just make sure you re-apply the fix after auto-updating NextGEN Gallery… plugin function overrides at a WordPress install level is still only a dream.

  11. November 21

    Thank you so much for sharing! I really appreciate your time and expertise. What an easy solution to a very frustrating problem. Yours was the only advice that was helpful to me…thanks!

  12. November 24

    Awesome Carolyn, big thanks go out to the original developers for including the source commenting otherwise I’d never have found it.

  13. November 30

    Hi!

    I also just came over this problem. Thanks god, someone posted a link to here at the wp forum. You really solved me a lot time! And only because of 2 slashes…

    Thanks a lot for making this public!

    Tom

  14. November 30

    Thank you, you save hours of my live))
    by the way, file name is gd.thumbnail.inc.php

  15. November 30

    Hey Delpher, thanks for the update I’ll do that now. Glad this fix still holds up!

  16. November 30

    You might have to deactivate the plugin and the reactivate it for this to work.

  17. Josh
    December 1

    I’ve had the same problem as described in the post. Unfortunately, this fix didn’t work for me. I’ve also tried altering the memory_limit with .htaccess but then I get an error 500 right away. I asked my host (one.com) and they told me that they don’t allow users to change the memory_limit. To me, that sounds weird, since it’s the first host that I’ve come across that limits their users to just 24M. But hee, at least they’re cheap.

    So, I still get an error with pictures over 600px wide and portrait oriented pictures almost always give the fatal error.

    I’ve really had it with this! The first couple of hundred (300) photos worked fine. Is there a workaround or a way to do this while using less memory? Or should I consider changing hosting?

  18. December 1

    Hi Josh,

    That 500 error indicates your hosting provider does not allow you to alter php.ini values, contact them directly and get them to increase your memory_limit value.

  19. December 8

    Thank you for this fix!

  20. Marcel Rondel
    January 3

    Thank you for this easy fix! I only wasted an hour trying to manipulate memory size with .htaccess. But I’ve learned to start searching the web in case of strange error reports. By the way: your name is very Dutch :-)

  21. January 5

    Was exactly what I was looking for, thanks!
    They should make this an option in the plugin itself…

  22. January 22

    Worked perfectly thanks!

  23. February 6

    That did the trick! Thanks!

  24. February 16

    Lovely! Thank you so much for your to-the-point help!

  25. February 22

    Hi!
    I have a question: If I put away the two // then i receive this error:

    Parse error: syntax error, unexpected T_STRING in /var/www/web25/web/fotos/wp-content/plugins/nextgen-gallery/lib/gd.thumbnail.inc.php on line 160

    What shall I do now?

  26. February 28

    Thanks!!!! I was killing myself trying to figure this one out!!! This solved it for me right away. Awesome.
    Cheers.

  27. March 5

    Thanks for this post. I’ve been searching for the solution for a while.

    Thanks again.

  28. philipp
    March 22

    Thanks for the entry. Initially I got this one:
    img.png (Error : Exceed Memory limit. Require : 80.13 MByte)

    After doing the modifications as described above, I now get following error:
    Fatal error: Out of memory (allocated 74186752) (tried to allocate 17044 bytes) in /www/htdocs/user/v3.1/wp-content/plugins/nextgen-gallery/lib/gd.thumbnail.inc.php on line 179

    Even adding “php_value memory_limit 256M” to my .htaccess doesn’t work. Could anyone help me, please?

  29. March 30

    Thanks a lot.
    After moving my Blog to another Server i got this problem and solved it with your hint.

    Kind regards,
    Michael

  30. March 31

    Your instructions worked! That’s saying a lot for tutorials these days – I found you when I encountered this problem working for a client by Googling “how to increase server memory for nexGEN gallery” — FYI

  31. Grant Z
    April 6

    That did the trick! Thanks so much!

  32. Padraig
    April 13

    Been bothered by this issue for awhile thanks alot of the solution.

  33. April 13

    Amazing. I actually held a post that should have gone out by Sunday morning trying to fix this and your solve simply had it working in a minute.
    Thanks for the lifesaver.

  34. April 17

    The result of this left me with: Fatal error: Out of memory (allocated 69206016) (tried to allocate 19968 bytes) in /home/flank/public_html/aquadetail/wp-content/plugins/nextgen-gallery/lib/gd.thumbnail.inc.php on line 351

    I’m going to comment back out that line… Thanks though!

  35. April 17

    Hey Devin, that means your hosting comany is limiting your memory. Contact them to increase it then you can make the same change again.

  36. Martin Stehle
    April 19

    Great aritcle! This simple solution made the upgrade of server memory and paying more fot it monthly to my provider unneccessary. Thank you very much!

  37. April 19

    Hey Martin, feel free to send a beer my way in that case from the donation form in the footer region. ;)

  38. Patrik
    April 23

    After taking away the // I still get “dsc_0004.jpg (Error : Exceed Memory limit. Require : 64.35 MByte)” :S:S why is this?

  39. April 24

    Thank you so much. I found your post in a Google search and was able to quickly eliminate the errors and get it going.

  40. April 29

    HI Michael,

    I will join here long list of gratitudes and say – thank you for sharing this with rest of us.

  41. Pargudo
    April 30

    Thanks! ver useful for me!

  42. May 21

    Michael, thanks. Worked a treat. I wonder if I’ll have to do this again when the plugin’s updated?

  43. Hey Rob,

    Yes you will need to apply this for each update to NextGEN Gallery, until a switch is added to the database to check this will remain so.

  44. May 21

    Thanks again, Michael :)

  45. Food Workshop
    May 25

    After I saved the photos in a compressed size, your fix fixed the problem. Thanks so much! (spent a whole day on this…)

  46. Thanks great tutorial, increasing the memory limit this way is easy and it worked for us.

  47. June 13

    Hey, I just wanted to point out that you don’t actually need to delete all the images and re-upload them. If you go into the “Manage Gallery” page and select your album(s), then select ‘Create New Thumbnails’ and apply it will re-create those thumbnails for you.

    Cheers!

  48. June 15

    Thanks for this.

  49. Ed
    June 22

    Thanks buddy! Only solution that worked out of about 8 that I tried!

    BTW it was on line 321 for me (maybe notepad++)

  50. June 30

    Thanks, a real help!

  51. Vladeta
    June 30

    Again, thanks for this help!

  52. July 1

    Like many other people above me, a big thank you for this simple fix.

  53. July 12

    Hey Adam, good point. Times have changed since this post was released.

  54. Mtx
    July 14

    You’re my hero. tks

  55. AC
    August 28

    Hey, thanks so much for the fix! I wish NextGen uncomment that line by default. That would have been so helpful.

Trackbacks

Leave a comment

The perfect comment is interesting, on-topic and/or highly amusing.