This tip is for anyone using TimThumb (aka “thumb.php”) either directly or indirectly via a WordPress theme (WooThemes uses it a lot) and is not having their thumbnails successfully generated.
I have run into this 3x in the last few years and ever time I forget the solution and have to re-find it, so I’m posting it here to help anyone else out running into the same issue.
Here are the juicy tidbits in easy-to-browse-format if you are coming in from Google:
- TimThumb is a PHP script used for zooming, cropping and generating thumbnails (typically 100×100 pixels) from images released under a GPL2 license.
- You can always download the latest version of the single PHP TimThumb script from here if you need it: http://code.google.com/p/timthumb/source/browse/trunk/timthumb.phpNOTE: Many WordPress themes (and likely others) use TimThumb internally to generate thumbnails (like WooThemes). There is a chance the TimThumb PHP file has been renamed in your install to something like “thumb.php” – double check when updating your copy of TimThumb.
- TimThumb uses the PHP-GD extension. If it’s not installed (as always happens with me) your thumbnails will silently fail to be generated.
Debian TIP: ‘apt-get install php5-gd‘
CentOS/RedHat/Fedora TIP: ‘yum install php-gd‘
- By default TimThumb reads and writes to the /cache and /temp sub-folders under the directory the PHP script is currently contained in. Your web server will need full read/write access to those two subdirectories.
Fast-and-Dirty TIP: ‘chmod 777 cache‘ and ‘chmod 777 temp‘
More Gooder-Betterest TIP: Find the user account that your web server runs under (likely ‘apache’ or ‘http’ or ‘www-data’, you can use the ‘top’ command and look at the user-process column for your web server process to see who it runs as) and give full read/write permission to that user to the cache/temp directory so it can use it as it needs it.
- Reader ridhoyp wanted to know how to configure TimThumb to resize images from a different domain (e.g. static.mydomain.com and mydomain.com), fortunately he found the solution online already.
NOTE: Many people have reported problems with their wp-content folder or timthumbs.php script itself are ‘chmod 777′, try using ‘chmod 755′ instead if you are still having problems.
And that should do it — if you are running into more complicated issues like the PHP script failing to even execute you might have a setup problem. Post a comment and I’ll see if I can help.
Update #1: A tip from reader Jeff is to use ‘chmod 755‘ instead of 777 as using 777 can cause problems with some server’s security settings (too open to trust).