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!

32 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.

Trackbacks

Leave a comment

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