217 thoughts on “Using TimThumb part 1: Getting Started Leave a comment

  1. Hi,

    I’ve used timthumb a lot of times, but this time its not showing the images.
    Its just showing a link, and after trying to open that link I get this error:
    Could not get a lock for writing.

    You can see that in the following link: http://www.everify.com/resources/wp-content/themes/eVerify/scripts/timthumb.php?src=http://www.everify.com/resources/wp-content/uploads/2011/07/Property-records.jpg&h=150&w=150&zc=1

    My page that I get the above link is:

    Its the testing link there under the red written “testing”

    I’d be glad if you gave me a small hint.

  2. Hi,

    my problem is:
    A TimThumb error has occured
    The following error(s) occured:
    Could not find the internal image you specified.

    Query String : src=http://www.stoneitaliana.com/wordpress/wp-content/uploads/2012/03/aaa.png&h=&w=662&zc=1
    TimThumb version : 2.8.10

    Can you help me?
    Thanks a lot.

  3. Well, I was hoping there was a way that the script could append a relative URL and make it an absolute URL, but I don’t know how to program that. So I just manually made the change on all the posts on my site. Fortunately, there weren’t that many. TimThumb is working great again!

  4. I have installed timthumb on a child theme based on TwentyEleven but I’m getting no thumbnail. My callup has a “alt name” in it and the alt name is showing up for each of three test thumbnails, but the images aren’t coming up.

    I looked at my source code and it’s looking for a scripts folder in TwentyEleven while it’s trying to call up an image from my child theme. No wonder nothing is working! But, my scripts folder is in the child theme where it belongs! I double checked my site and it’s properly using the child theme.

    My template code is this: <img src="/scripts/timthumb.php?src=ID, “thumb”, $single = true); ?>&h=150&w=150&zc=1″ alt=”” width=”150″ height=”150″/>

    My source says this:

    Note that it’s looking for the timthumb script in TwentyEleven.

    Apparently, the issue is that I need my ‘template_directory’ to go to my child theme, not TwentyEleven. What do I need to do? How do I achieve this? Is this a timthumb issue? It seems that ‘template_directory’ should go to my child theme.

  5. It looks like you must be stripping out anything that appears to be a URL or something, so my examples didn’t get displayed properly above.

    Anyway, my template PHP is calling up the ‘template_directory’ to look for the timthumb script, but my source code shows that it’s looking for it in the parent theme, not the child theme. I have no script in the parent theme (properly so) but I have it in my child theme with CHMODs set appropriately. And my child theme is activated.

  6. I found the solution. Someone on another forum explained that for child themes, one should use ‘stylesheet_directory’ instead of ‘template_directory’. Stylesheet_directory refers to the stylesheet currently in use, that is, a child theme in my case.

    I’ve got my thumbnails! Thanks for the script. I have a client who’s going to be very happy.

  7. Pingback: Test DOKO-Kombinat Nagelik 1985
  8. I see a lot of gallery plugins and carousels using TimThumb, is there a way to specify WHICH images of the gallery to display when it comes to displaying the “featured” image within the WP native gallery? Logically it should grab the first image, but in other cases, its grabbing a random one, not sure if this can be called upon from within TimThumb or the plugin itself, I’m trying to figure out how to simply point it to the first image of the gallery and not a random one.

    1. Hi – All TimThumb does is resize images, it has no effect over the way things are displayed or their order on the page – that’s all done by WordPress.

      Please note that TimThumb isn’t directly associated with WordPress. It’s used with WP a lot, but it’s not a plugin. It’s just a script people use 🙂

  9. Gotcha, and thank you for the clarifications, I guess limiting it to WP was an understatement, I’ll address the issue with the plugin developer to see whats up as it doesnt make sense lol Thanks Ben and yes GREAT script!

  10. Pingback: AutoFocus Previous Post / Next Post Image Thumbnails | TQuizzle.com
  11. I am using timthumb to crop an image from another website. The image is a haze and fire danger rating map which updated daily.
    I am trying to make timthumb crop the image on daily basis (since the map is updated daily). I see sometime timthumb use the cached image and doesn’t update to the newest image of the day.
    I don’t know how to fix that. Please advise,

    Thank you very much.

    P.S. The website address (dummy website only): http://civildreamer.com/haze
    The image i am talking about is the one on the middle column which titled “Regional Haze map “

  12. I’m making a new wordpress project right now the theme uses timthumb unfortunately the images are not loading some does and many don’t. When I create a new post with single or several images each size 200kb resolution max width 900px max height 750px, it does not load right away timthumb error Could not get a lock for writing then after 15 mins it loads but some times it doesn’t. I already change permission to 777 on cache folder but did not work tried I all the tricks to make timthumb work but to no aveil then I decided to install it to a different hosting comp. and had no problems at all images load without any problem so I issue a ticket on my hostting company ( where timthumb does not work) here is what they said.

    The problem is that the function that timthumb is trying to use, flock() with LOCK_EX, when generating the thumbnails, is not compatible with the Grid Iron architecture. The reason why is because Grid Iron makes use of NFS storage. This is part of what allows us to provide the scalability and redundancy of the Grid Iron platform. The flock() function is not compatible with NFS. I looked briefly into the source code of timthumb, and it is indeed trying to use flock():

    if(flock($fh, LOCK_EX)){
    @unlink($this->cachefile); //rename generally overwrites, but doing this in case of platform specific quirks. File might not exist yet.
    rename($tempfile4, $this->cachefile);
    flock($fh, LOCK_UN);
    } else {
    return $this->error(“Could not get a lock for writing.”);

    There is more information about flock() not working over NFS here:


    So, TimThumb will not be able to reliable obtain a file lock using the flock function, so you should see if TimThumb has an alternative file locking mechanism that would be compatible with files stored on NFS.

    Can you please help I don’t have any idea what to do any more

  13. Yep, TimThumb does not work on NFS because it tries to use flock() with LOCK_EX – Exclusive locks don’t work on NFS. Author should fix this.

  14. ok, so i this super annoying problem.
    i want my thumbnails to be 250×250 square
    but my images are always cropped to 300×167
    even tough in the thumbnail settings i selected full size (250×250)
    and i’ve seen you’re demos on how to specify the size
    but i’m totaly new to wordpress and i don’t understad where should put the code
    THIS is my blog

  15. Have you seen a solution to the following problem?

    When I have the full path to the image included in the timthumb.php request, like this:

    The image doesn’t show up and it generates the default 404 WordPress error page. (You can click on the link to see for yourself actually.)

    However, when I click on the link and get rid of the ‘http://jennacomm.com’ from the src variable, it displays the image just find in the browser.

    This is giving me a migraine as I’ve tried just about everything every site out there has suggested to no avail.

    Changed permissions to 777, which I didn’t want to do because of the security hole, but I did, and that didn’t work.
    GD Library is installed.
    Cache is there and that appears to be working.

    Any idea?

  16. i used it on my website but i found many problems, images dont appear on the website and hadn’t been created on the cache folder

  17. Pingback: TimThumb – PHP Image Resizer | Siterevista.com
  18. Hi, Ben
    Thanks for the article.

    Random question — I’m just starting to build my site, and it’s built on a lot of timthumb stuff.

    Is there ANY way to make a post without an image without having timthumb put an obligatory “broken image” sign. Sometimes I just don’t want a picture there, but it demands it — at least in my setup.

    I did a tiny 10×10 transparent thing, but of course when I do that timthumb blows it up to be this massive blank space, which isn’t helpful either.

    Anywho, just thought I’d ask an expert 🙂

    1. You need to edit your theme so that it doesn’t try to embed timthumb if there’s no image assigned to the post.

  19. Howdy,

    I am using the default lightbox on Super Skeleton to enlarge images and i believe the lightbox is Tim Thumb.

    The lightbox allows users to share the file via Facebook or Twitter – I would like the ability to add more networks like Pinterest etc.

    How can i find where to do this in the wordpress backend pretty please?


    Kat 🙂

  20. w and h – width and height. Totally optional but also almost essential, few people want the default sizes. The width and height can be any value, TimThumb will enlarge or shrink as required.

    With huge sized images, some people may want to automatically activate the MAX_WIDTH or MAX_HEIGHT config settings to save time manually processing images, especially if loaded by third parties, instead of the 100×100 default if w and h omitted, i.e. display at original size unless MAX_WIDTH or MAX_HEIGHT occurs.

    Thanks for your time on TimThumb, brilliant,


  21. Hi,
    This is a great script and i’ve been using it for a while, however i found that the script makes a lot of caches that are 0b in size. What is the reason for that?

  22. If u want to use friendly url in your website, you can use this script in the .htaccess.

    RewriteRule ^(thumb|image)/([0-9]+)/([0-9]+)/([0-9]+)/([a-zA-Z0-9-./:/&?=]+) Thumb2.php?w=$2&h=$3&q=$4&src=$5

    I create this format for me. For example:

    Without this regex:

    With this regex:


    you can use thumb or image.

  23. Hi, I used this script in my latest project. Everything works good for me, but when site/page load first time that time some image are not load. When refresh it then after all images are load. If you have a any solution for this then please tell me. The client is on my head any one have solution than please reply me…thanks…….

  24. I guess its a goodbye to timthumb.php file from all web hosting companies.

    Till April, 2014, it was working on my site http://www.timesofassam.com. But it doesn’t work now.

    I have tried so far:

    1] All fixes found by googling around.
    2] Changed hosting to 4 hosting companies.
    3] Tried VPS & Dedicated server too.

    But no luck.

    Its time to think about alternative of timthumb.php


    Dhruba Jyoti Deka

  25. I love this image gallery script.
    I’m looking for image sorting edits so I can have latest modified image load up first. Is there a work around?

    1. Hi – TimThumb is just for resizing images. It doesn’t do anything on the website itself. You would need to modify your website to add sorting.

  26. Hi Ben, thanks for providing amazing library. I read an article where you discourage people from using the library due to security issues. Please i want to know, is it still safe to use the library now after so many years. has the issue been fixed. Am using version 2.8.10

    Best regards

    1. Hi there – thanks for the message. As far as I know the latest version is secure but the code hasn’t been touched in years now so it’s possible that other security problems have been found that I am not aware of.

Leave a Reply

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