Skip to content

TimThumb Troubleshooting Secrets

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

lightbulbThis 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Cache Directory Permissions – the cache directory should exist inside the same directory as TimThumb. It should have permissions set to 777.
  6. 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.
  7. 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.
  8. 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).
  9. 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.
  10. 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.
  11. Image Formats – make sure that the images are one of jpg, gif, or png or they won’t be resized.
  12. 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

Hopefully with the hints and tips above you will be able to solve most common TimThumb problems. I plan to keep updating this list so if you have any other comments or suggestions just post in the comments and I will update as I go.

Share

403 Comments »

  1. Hi Getting Following error :

    A TimThumb error has occured
    The following error(s) occured:

    No image specified

    Query String : page=home_slider
    TimThumb version : 2.8.10

    I have used latest version of timthumb.php

    Can anybody please Help !!!

    Thanks in Advance

  2. Pingback: Migrating Timthumb
  3. I’m helping a developer get a new site up and running on one of a university server and we’re getting the 400/Bad Request error for the timthumb images. I’ve tried every trick in this thread but can’t find any issues on the server side of things (not ruling it out, but no server errors in log).

    If parameters in URL are stripped, images show, e.g.:

    Good request:
    http://depts.washington.edu/cirgeweb/wordpress/wp-content/themes/awake/images/activation/esof2012a.jpg
    Bad request:
    http://depts.washington.edu/cirgeweb/wordpress/wp-content/themes/awake/images/activation/esof2012a.jpg&w=567&h=334&zc=1&q=100

    Any ideas what could be causing this?

    • Ok, fixed this. I’d tried setting permissions to 777 and 755, turns out 664 did the trick. Web server did not like the executable permission setting.

  4. timthumb thows up an error when fetching images that have an apostrophe in the filename. The call is:
    src=”../timthumb.php?src=http://upload.wikimedia.org/wikipedia/en/f/f3/Don’t_Panic.jpg&h=35&w=35&zc=1″>
    and timthumb’s error report is:

    “Query String : src=http://upload.wikimedia.org/wikipedia/en/f/f3/Don%27t_Panic.jpg&h=35&w=35&zc=1″

    David

  5. Hi Ben, how are you? I’m really hoping you can help me.

    For the last year I’ve been running our photography company’s website on WordPress. Everything’s been running great and then all of a sudden a couple weeks ago our thumbnails stopped working for no reason at all. We hadn’t made any changes to the site, theme, or WP version.

    Here is an example of a problem page:
    http://siskphoto.ca/concert-photography/

    Since the site is a photography company site, the majority of it is photos and now none of our gallery thumbnails work, this is not good at all. =( The images are still there and if you click on the broken thumb, the image still loads up.

    I’ve done tons of research and checked everything mentions on your site too and I can’t for the life of me figure out what the problem is. I’ve looked at the permissions so many times too…. =(

    If you have any ideas what the problem might be I’d be forever grateful to you. Please help.

    Thanks,

    Erin Fraser

      • Hi Ben,
        Thanks for the reply.

        I’ve made a discovery. After putting a whole new WP installation on and trying a few test photos, it seems the only photos/thumbnails that work properly are the ones who have underscores in their file name. If they have dashes in the file name the thumbnail is broken.

        Have you heard of this happening before? Do you have an idea of how to fix it?

  6. So, I have TimThumb 2.8.11 working without a problem and thanx … it is a really nice, convenient script for what I need.

    My question is in regards to the cache files … do I have to create a script that will delete them periodically? or does TimThumb do that itself?

    just curious as I do not want to have thousands of state cache files sitting around on my server

    Thanx

    Gordon

  7. Hi there,

    I recently moved http://www.footy.co.za to a new host, but for the life of me, can’t get timthumb to work.
    I have gone through all the permissions & setting of folders, but still having no joy. Is there something I am missing ?
    Any help would be greatly appreciated !

    Thanks in advance
    Marc

  8. To all other readers, do not set your `cache` folder permission to 777, set it to 755. You’ll get easily hacked if you follow the permission he posted here.

  9. Great script!

    Question – Whats the best way to keep updated on the latest releases?

    For example i just found out today that you went from 2.8.10 to 2.8.11 last month…

    Without checking in every day I don’t see a newsletter or anything that would send me notification of these changes.

    Please advise.

    Thanks,

    Jay

  10. Hey :-)
    Thanks for your work and sharing with us! I’m using Website Screenshots and spent some time searching for the reason why they’re always cropped to 800 x 600 – no matter of the adjustments in WEBSHOT_SCREEN_X / WEBSHOT_SCREEN_Y

    It’s easy: Tell CutyCapt this resolution too! ;-)
    In timthumb.php (2.8.11) add –min-width={$screenX} –min-height={$screenY} to $command at line 970 and 972 and you’ll get what you want.

  11. Hi Ben,

    thank you for creating TimThumb!

    I have the problem that with every request a new cache file ist created. When I Refresh the page a new cache file ist created (for one image) every time which results in a lot of cache files for the same image!?

    For example image “test.jpg”:
    Request 1 -> Cache file is: ./cache/timthumb_int_46b8d758e92c92194fe777812b5e1256.timthumb.txt
    Request 2 -> Cache file is: ./cache/timthumb_int_55e1665e99490a3cdf486ee69294e9ba.timthumb.txt

    It seems that the earlier created cache file ist not found by the script!? Or is this normal behaviour?

    Thank you in advance and best regards,
    Frank

  12. Hi Ben,
    I have follow all the instruction, but I come up with this one:

    Warning: tempnam() [function.tempnam]: SAFE MODE Restriction in effect.

    A TimThumb error has occured

    The following error(s) occured:
    Could not open the lockfile for writing an image.

    Any Idea? Need Advice.

    Thanks.

  13. Hey Ben,

    Wondering if the issue with the thumbnails not appearing is solved. Just shows a thing empty box there the thumbnail is supposed to be. Was working with the test images I was working with, but once I started uploading the images I need to use, the thumbnails are not showing. Figured out everything else I need but this.

    Please let me know.

  14. Does timthumb require touch() to function properly?

    Been beating my head against a wall for some time trying to get it to stop erroring out. Wondering if that is why?

  15. So it turns out that the script breaks if you don’t have touch() enabled…even though as far as I can see it only uses touch() for error checking. In other words if touch() is disabled (common for security) the error checking effectively breaks the script even if it’d otherwise be working fine.

    Please include this in your troubleshooting guide! I wasted probably 5 hours pulling my hair out trying to follow the (non applicable) error messages, thinking I had somehow reconfigured something.

    If anyone else runs into:

    Warning: touch() has been disabled for security reasons in /home/fresoil/public_html/templates/ammon/php/img.php on line 200

    Warning: touch() has been disabled for security reasons in /home/fresoil/public_html/templates/ammon/php/img.php on line 469

    Warning: Cannot modify header information – headers already sent by (output started at /your/directory/structure/here/timthumb.php) in /your/directory/structure/here/timthumb.php on line 418
    A TimThumb error has occured

    The following error(s) occured:
    Could not create the index.html file – to fix this create an empty file named index.html file in the cache directory.
    Could not create cache clean timestamp file.

    Query String : src=http://somewhere/image.png&w=290
    TimThumb version : 2.8.11

    Here is what you do to fix it:
    Either enable touch on the server, or simply comment out lines 200-202:

    if (!touch($this->cacheDirectory . ‘/index.html’)) {
    $this->error(“Could not create the index.html file – to fix this create an empty file named index.html file in the cache directory.”);
    }

    and lines 461-463:

    if (!touch($lastCleanFile)) {
    $this->error(“Could not create cache clean timestamp file.”);
    }

    This should be fixed or at the very least documented.

    • Hi Emma – your images do not have an image url supplied. You will have to ask your theme supplier how to specify the image with your theme.

  16. If an image is not working and you are using WordPress, you should also check the Security…Tweaks…Server Tweaks. If “Filter Suspicious Query Strings” is checked, it may prevent timthumb images from being displayed and instead gives a 403 – Permission Denied error.

  17. The last secret says: “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″

    666 means the public can write this file, my question is why does the public needs to write this file?
    Shouldn’t 664 be enough?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

I seem to find myself working with Youtubes thumbnail images quite a lot (for instance on Miniclips videos section) – and I am always having to go searching for the parameters to use to generate those thumbnail images. So I […]