More information →
I often get asked questions about TimThumb and why it doesn’t work in certain situations. I can generally tell what is wrong with the script within about 60 seconds of being sent a demo url. Below are my top tips for debugging TimThumb issues.
Keep TimThumb up to Date
This is super important. TimThumb should always be kept up to date. I regularly publish bug fixes and improvements and often the problems listed below will actually be fixed already if you only used the latest version. Just grab the latest version of TimThumb from Google Code and upload it. Is your problem fixed now? If so then great! 🙂 If not then read on and we’ll sort it out!
If you’ve not heard of TimThumb before then it’s a simple PHP file used to resize images dynamically. You can read more about it, and find some ‘getting started’ style hints and tips on the TimThumb Project Page.
TimThumb Secrets
- Right Click > View Image – If an image isn’t loading then this is the first thing you should do. 9 times out of 10 it will tell you what the problem is in an easy to read error message.
- Supply an Image url – this is surprisingly common. TimThumb is clever, but unfortunately it needs to be fed image paths so that it knows what to resize. This is pretty fundamental, you can read more info on getting started with TimThumb here.
- urlencode(url-with-parameters); – if the image you are resizing is a dynamic one (ie, it has &skdh=khdkfs&ksjdsjd=ksh) then it is unlikely to resize properly. Simply change your image url so that it is wrapped in a call to the urlencode PHP function. This is something I would always recommend doing as it will encourage TimThumb to work in more situations.
- Cache Directories do not exist – For TimThumb to work properly you need to have a cache directory called cache sitting alongside the timthumb.php file.
- Cache Directory Permissions – the cache directory should exist inside the same directory as TimThumb. It should have permissions set to 777.
- More Cache Directory Permissions – if 777 doesn’t work then you may find 755 is ok. It’s worth a try, but not something I have seen very often.
- Cross Domain Request – for security TimThumb restricts cross domain requests. Certain websites, such as Flickr, are allowed by default, but if you want to load an image from another website then you need to make sure it’s added to TimThumb. You can read about cross domain TimThumb requests on a previous post.
- File Permissions – some web hosts won’t execute PHP code if it sits in directories that have permissions set to 777. So make sure that any directories ‘above’ the timthumb.php file are set to a normal level of permissions (644 is good).
- Use with WordPress mu/ multisite – It’s a common misconception that TimThumb doesn’t work with WordPress Multisite. That’s not true at all. All Pro Theme Design themes use TimThumb and work fine with the multisite version of WordPress. To make it work you need to customise your theme, and there’s info on this in my tutorial here.
- Server Requirements – this should go without saying really but TimThumb requires PHP and the GD image library. These are really really common so you shouldn’t have any problems. If you find yourself without these installed then ask your webhost and many will install the software for you – if they don’t do the installation it’s probably worth considering a new host.
- Image Formats – make sure that the images are one of jpg, gif, or png or they won’t be resized.
- index.html – to prevent the cache files from being browsable an index.html file is created in the cache directory. This file should have it’s permissions set to 666
Was it good/ useful/ a load of old rubbish? Let me know on Mastodon, or BlueSky (or Twitter X if you must).
Link to this page
Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.