Home/ Journal Bens Projects Binary Moon Archives About Ben Gillbanks Subscribe to Binary Moon Updates

Subscribe to Binary Moon Website Updates, it's Free and Easy to Stay in Touch

Search Binary Moon

Search Binary Moon

Using TimThumb part 1: Getting Started

TimThumb has always been built with simplicity in mind. However there are a few things it can do that have not been exposed before.

Inspired by a comment from RBhavesh I have decided to write a series of posts in which I will show you how TimThumb should be used - and introduce some new functionality.

In this post I will discuss the basic usage of the script - the minimum parameters to send, and some examples of usage.

Basic TimThumb Setup

Getting TimThumb to work is pretty straight forward. You need the php file, which you can download TimThumb from Google code, placed in a folder on your website. In the same directory as the timthumb.php file you need to add 1 directory. The directory should be called 'cache' and needs to have its file permissions set to 775.

Simple explanation

TimThumb is a single php script that has a series of parameters passed to it through a query string. Whilst TimThumb has found a home in WordPress themes it is by no means limited to them - TimThumb can be used on any website to resize almost any image.

Requirements

For TimThumb to work your web server should support the PHP programming language and the GD image library. In all the time I have been developing TimThumb I have yet to find a server it wouldn't work on, so there's a pretty good chance that TimThumb will work on your server.

In addition you should create one directory for saving thumbnails. This directory should be in the same directory as the TimThumb script and should be named cache. The cache directory should have it's permissions set to 775.

Note that the cache directory should be the only file/ directory with 775 permissions. The script, the scripts folder, and any other folders should have the default value for your server.

Basic Parameters

The parameters below are the main ones used. With these you can resize almost anything.

  • src - this is the only required parameter. Absolutely everything else is optional. If you only specify the source property then the image will be cropped/ resized to the default dimensions (which are 100 x 100)
  • 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.
  • q - quality. This specifies the compression level of the images being cropped/ resized.

I have put together a page of examples with code, so that you can see all you need to know. You can view the examples here.

With just these parameters you can do everything you need to with the average TimThumb image. In the following parts I will outline the more advanced features of TimThumb including showing off some of the latest functionality.

In the next part I will be showing how to use some of the more advanced features in TimThumb, including how to make images greyscale and other filters.

157 Responses to “Using TimThumb part 1: Getting Started” Leave a reply ›

  • Dang! *blushes* You mentioned me in this post.

    To be honest, most of us Premium Theme developers owe you big time. What you've built is genius and extra ordinary. I can't praise this enough. Here's how this can be taken to next level.

    1) ofcourse the folders needs to be given 775 / 777 permission. 'Somehow' if we can find out a way to skip this step, it would take off atleast 25% of our support burden :) . I know you might be facing this same problem at Pro Theme design as well.

    2) A way for the user to decide from which direction he/she wants to crop the image. Top left, top right, middle, bottom left or bottom right?

    This is just a wishlist, nice to have stuff that'd make this revolutionary script even better. It's sad you have not received enough credit for this as this script works behind the door.

    Kudos to you mate.

    • Profile

      Thanks :)

      Number 1 is an ongoing problem. Not sure how to fix it but I think there may be a couple of things that will help reduce the problem.

      Number 2 - keep reading this series of posts :) There's actually a couple of things already available that I don't think people realise are possible, and the one you mentioned will be released in the next couple of weeks.

  • I am trying to use this in my site but it display images upload in directory wp-contents/uploads , most of the images in my posts are from external site or flickr . It is not displaying thumnail from those site. Is there any thing to make generation of thumbnail from them possible ?

  • Fantastic!, I've been using this script in it's basic form for a long time, I can't wait until the next installment - looking forward to it thanks

  • I'm pretty sure you need to fix timthumb to get it to work in vs. 3.0 of WP. I've actually been corresponding with the Author of the script (Darryl) on getting him to release an official version upgrade.

    In the meantime, readers can check out instructions on how to fix the script here:

    http://wptricks.net/...fix-readfile-problem-on-timthumb/

    • Profile

      Hi - the script works perfectly with WordPress 3, the version of WordPress doesn't matter. The problem is in the script itself, and this change is being added to the next version.

      FWIW The author of TimThumb is actually me, and the person you have been talking to is Darren - who forwarded your message to me :)

      • Hey Ben!

        Well.. Glad that's been straightened out! :-)

        I was under the impression there was a problem integrating the script into WP 3.0 and hacks are abound (such as the one I posted).

        I subscribe to your RSS feed so I take it I'll be notified when you release the new & improved version of TimThumb.

        Thus far, it's the easiest and most effective script to accomplish on-the-fly resizing of images.

        Good to meet you!

      • Profile

        Hey Daniel. There's no problem with TimThumb and WP3.0, I use it here on Binary Moon just fine :) I am going to be writing a series of posts about TimThumb (this is the first) and will announce when I release major new versions (not small bug fixes) so you will see the big updates come through ... and there will be one shortly.

  • my first exposure to timthumb was after I purchased the nominate theme. It's very neat! I look forward to future posts on it. Maybe I'll find if there's a way to add a custom loading or default image if it can't load something... :)

    • Profile

      Hey there - glad you like it, and thanks for buying Nominate :)

      The default image is really up to the software. TimThumb just resizes stuff but you can have some code in your website that says (pseudo code time)

      If theres an image
      load timthumb image with image I found
      else
      load default image

      If you were to use the Elemental theme, without Nominate, then you would see this code is in place. I demoed it in the recent Elemental update video that you can see here.

    • Where is

      function displayError($errorString = '') {
      header('HTTP/1.1 400 Bad Request');
      die($errorString);
      }

      Put this

      function displayError($errorString = '') {
      $img = @file_get_contents( "no-img.png" );
      header("Content-type: image/jpeg");
      echo $img;
      }

      • Profile

        Thanks for the suggestion. The problem with that is it doesn't tell me what error has caused TimThumb to error out which is the whole point of that function. The theme or website should know whether there is an image to resize or not (it's 1 or 2 lines of code!) and should then supply a default. It's not up to TimThumb to do that.

  • How to set the second try access the thumbnail image are direct to cached thumbnail?

    why i ask this, is to reduce request http to timthumb.php.

    Regard,

    dgrut

  • I have confusing for 3 day because timthumb in my website doesn't work, But now everything is fine. Thanks for this blogs administrator.

  • Awesome! I've just found this script (bit late to the party I know) and it's going to make using custom fields in WordPress so easy and so great.

    Once again I'm reminded of the generosity and community spirit online. I love it!

    Thanks so much for sharing this awesome gift!

  • Hi,

    I moved my website to another domain name and server and now none of the thumbnail images show up and I have tried to the delete the cache folder but no success.

    Any chance of getting this to work?

    Thanks,

    Dennis

    • Profile

      If the domain name has changed then it's likely you will need to update the TimThumb urls to match the change.

      • Thanks for your fast reply Ben,

        I am currently using TimThumb as part of a wordpress theme:

        What exactly do i have to change? Or it it located in the database?

        Thanks,

        Dennis

        See below for the source of "thumb.php"

        http://www.mediafire.com/?yu49n227i707nmi

      • Profile

        It depends how the theme works and the image is stored but my guess is it's a custom field in which case the changes are all in the db.

      • Hi Ben,

        I have gone through the database and edited all the entries. I have also tried to create a new page with a newly uploaded image (it exists) but it still says "file not found". If I go to the image without thumb.php it works but otherwise it doesn't

        Is there anything else that I can try?

      • Hi Ben,

        After doing some more debugging I discovered that If I change the original path from this:

        thumb.php?src=http://mysite.com/dir/wp-content/uploads/2010/09/forward-to-a-friend-icon.png&h=200&w=350&zc=1&q=80

        to this:

        thumb.php?src=http://mysite.com/wp-content/uploads/2010/09/forward-to-a-friend-icon.png&h=200&w=350&zc=1&q=80

        It works but why is it doing this everything else is working so the path must be correct otherwise wordpress would not work. But there must be something that is causing this.

        Thanks for all your help so far.

        Kind Regards,

        Dennis

      • Profile

        not sure - I assume you are using a multisite version of WordPress?

      • Hi Ben,

        Well after moving servers yet again it now seems to work without any modification which means it must have had something to do with the last server configuration.

        Anyway thanks for your reply's and this nice "plugin"

        Thanks,

        Dennis

  • I would like to specify the the aspect ratio be maintained at a certain max. width, max. height. I don't think timthumb can do this, but I'm having trouble with the code for it. Would you help me, please?

    Thanks!

  • Be sure thumb.php is not being cached with opcode caching such as xcache or APC. You can filter it from APC in your .ini file, here is more info re: APC opcode caching with WordPress:
    http://chrisgilligan.com/...ith-php-running-under-fcgid/

    If you are using W3 Total Cache, WP Super Cache or another cache plugin, you can specify filters for scripts or folders that should not be cached.

  • Hi, I love the script. It's really helpful.

    I have a situation where I don't want to use a default image for posts that don't contain any images.

    How can I remove the default image?

    -Add a CSS class that only applies when the script outputs default image?
    -Stop the script from outputting a default image altogether? How would I do that?

    Thanks again for the great work!

  • I'm using this on a child theme of the Kubrik theme (WP 2.9.2). I can't get the image to actually show. The code works and gives me the related post, but not the thumbnail. Any thoughts?

    The website is not live yet, so I can't link you to a working site, but I can send my single.php code over.

  • Hello, sorry to bring this up here.
    I've locally developed a website that uses timthumb and all worked fine. After moving it to my server all pre-server thumbnail calls are failing. New posts with new calls are fine. In the database the values all match, The images were ftp'd up in binary mode. I can't see a reason for why this is happening?!
    Cache directory has been test at 775 and 777.
    If i try and directly accesss an image the page just displays white with the img url.

    I get the impression that it's unable to read the file as if it is corrupt. I have uploaded them several times. Any ideas? It's an image heavy site so redoing all the pages is a big task. TIA

    • Profile

      Do you have a link I can look at? Without seeing it I'm not sure I can help. One tip - if you right click and open a broken image in a new tab/ window, then it should tell you what the error is.

      • Thanks for the tip!
        I've actually got it working now. If it helps anyone else.... the generated thumbnails were present and working when acessed directly, the original however had some how become corrupt - 0bytes on the server and uploading new copies just wouldnt work. Windows(7) was reporting these originals (which had been through timthumb) as inaccessible due to permissions (even though I'm admin and creator).

        I don't know exactly which part fixed it. I used the TakeOwnership.reg Windows7 context menu mod to retake/reown the uploads directory then I scrapped the server install, setup a new vanilla wordpress and uploaded the modified database as usual. Copied ONLY the wp-content folder. It now works perfectly - even bugs that should be there aren't. I tried manually reowning an image, uploaded, but that failed. So it was either the REG mod or theres code outside of the wp-content directory that was breaking it. I hope that helps someone else who might be having the same problem.

        Great job on timthumb, I gave up on WP years ago because of the poor image support. Now I use it for most sites. Thanks again.

      • Profile

        Glad you worked it out, and glad you're enjoying TimThumb :)

        Thanks for the kind words

  • Hi,

    I searched a lot before deciding to come directly to the source. Can´t find someone reporting the same problem as i have, so..maybe you, as the author of the script, can give me some tips as how to resolve my problem.
    My images show up, they just dont resize.
    Heres a link to a page where the images show up but don´t resize.
    http://locais.porto24.pt/...38;zc=1&q=80&bid=6

    I found that images outside the "files" folder get resized: http://locais.porto24.pt/...ntent/blogs.dir/6/aikido.jpg

    Thanks in advanced

  • Hi

    I wonder, does your script validate? I checked http://www.binarymoon.co.uk/demo/timthumb-basic/ and there were quite a few errors, some of them related to incorrect encoding of ampersands.

    • Profile

      Hi - The script has nothing to do with validation. The problems are how I did the code for that page. If I had bothered to spend the time to encode everything properly then it would validate just fine.

  • That was fast answering!

    I refer to the error concerning the output of ampersands as separators in the PHP. How do they output in your script?

    Thanks

    • Profile

      The TimThumb script doesn't output any html - all the script does is resize the images. The html on the page is the problem with the validation and the issues with that are unrelated to TimThumb.

  • Hey,

    I was just wondering if it possible to specify a default image to the script if no image is found.

    If you look at the theme I am using (Arthemia, url in name) the carousel still tries to use timthumb on no image. I have created a 404 image to go in place, but I cannot figure out how to get timthumb to load the default image if no image is inserted in to it.

    • Profile

      Personally I think this is up to the theme to specify. If there is no image available to be resized then it should either hide the image or show a default. Either way you would need to customise the theme to make this work.

  • just replying with notifications ticked!

  • Hello everyone .. how to set image height in code so this should apply to all website thumbnails .. sorry but i am not good in programing .. anyone please help .. thank you

  • Hi - Having a real problem with the thumbnails since a server 'upgrade/switch' at the weekend. TimThumb was working brilliantly before that. All the links to existing images are now broken and the script is failing somewhere. Host says GD image has been re-installed on new server. Cache and temp are at 777 (have followed all the advice above). Still no joy. Please help! Thanks.

    • Profile

      Getting a 404 on the images so either a) the image doesn't exist, or b) you have directories that are above the cache directory, and are set to 777 permissions. See here for TimThumb trouble shooting hints and tips.

      • Thanks Ben for such a quick reply, I checked with the theme developers a 2nd time, they recommended to make the Script and Cache folders 755 in case the server setting was the problem - so I changed those plus the "parent" folder and bingo! it works! I am so relieved. It's a great script - Thanks

  • Ben, thank you! Excellent script! I found it more flawless then SLIR (another smart resizer). At first I’ve been trying to set up SLIR for 2 days and it was all in vain. I don’t know why? And then I just suddenly found your Timthumb and… it works!!! perfect!
    I appreciate your code sharing! And whenever I’ll use Timthumb I’ll mention you and link to your blog!
    All the best to you!!!

  • Hey guys,
    Great plugin I think its the way to do thumbs in webapps with all kinds of sized thumbs being displayed.

    I was wondering though if its a good idea to add to the show_cache_file:

    header("Location: ".$cache_file);

    instead of reading the file in via PHP, I'm not 100% sure weather this would be faster then just using PHP but I just think if the image has already been cached then its a shame to go through PHP to retrieve it.

    No expert on this so critics welcome :)

    • Profile

      Hi John - thanks for the idea, that's quite clever actually. Unfortunately that probably won't make any difference. The issue is that unless the theme/ script stores the cache location itself you will always have to hit the php file to be able to work out if there is a cache file or not.

      I do have one idea that involves creating a function that will generate the cache file and return the cache name so that you can store it in your web app (in WordPress post meta for instance) and then display that instead of hitting timthumb every time. This, however, would be less flexible so may not be so good.

  • Hi Ben,
    thanks for your great script, it was part of a WP-Theme I installed, and I'm lovin' it.

    Is there any possibility, to tell your script to fit either the width or the height, and to stop fitting after the first one matches? I have a problem with photos in portrait mode or in a square crop, check out my blog, there are two pics, which are zoomed in a lot, and I wonder if this is the only solution for such photos, if I want to keep the aspect ratio...
    Sorry for my bad English, don't know if you get what I mean.

    Thanks again, hope to hear from you...

  • I recently migrated from Blogger to WordPress. My site is techlikes.com. I'm using "Arthemia premium" theme v1.0. Since I found that the TimThumb script in the theme folder is old, i updated it with new TimThumb script from googlecode site. But the images are not showing up and no error crops up. Can you please check what is wrong ? site is techlikes.com and mail id : rama.geek AT gmail.com

  • I have a problem with photos in portrait mode or in a square crop, check out my blog, there are two pics, which are zoomed in a lot, and I wonder if this is the only solution for such photos!!

  • Hello,

    Great script, useful and very simple to use!

    The only thing it's missing is a way of dealing larger files you don't want to crop and of course, distort them.

    Imagine you are printing some logos. You can't cut parts of a logo and of course you must keep the proportions of the original logo. If there is a jpeg file it should use some standard fill color and, if it's possible, it png files it should use transparent background.

  • The case Jan and me were talking is when the image needs a fixed size where one cannot use just one of width/height parameters to keep the original w/h ratio.

    The logic could be like this:
    if original_width/new_width larger that original_height/new_height
    then use new_width and calculate height to keep original w/h proportions;

  • This is nice, thanks!

    I'm already using the latest version. Could there be a parameter to choose the color it's using on blank spaces of shrinked JPG files? (it uses black now; transparent png24 files are working fine)?

  • Hello Ben, thanks for making WordPress worth the trouble. They should consider hiring you or buying your script because their thumbnail script is complete garbage.

    I have a simple question:

    Is it possible to move the center of the image to the top or bottom, instead of the exactly in the middle?

    Thanks!

  • Hi,
    I love your script, really do, once I got my head around it the first time I love to use it to resize all my photos.
    One problem I have come across is that its not W3C Valid. Please could your look into this.
    Thanks
    Rachel

    • Profile

      Hi - the script it totally w3c valid. In fact there's nothing to validate with the script - the issues are with how you are using it so you will need to change the implementation method to make sure it validates properly.

  • Love the script - been using 1.12 for a while now... but whatever I do I can't get 1.25 to work for me. I've copied the new script over, made the new temp folder, and checked everything three times but it simply won't work. If I revert to 1.12 though, it's fine. Any thoughts? Here's the line in my template file that calls the script:
    <img src="http://URL-TO-FILE/...00&h=255&zc=1&q=100" id="leadpic" alt="">

    • Profile

      Hi Andrew - your code looks fine. What error do you see when you use the latest version of TimThumb? Just open the image in a new tab and there should be some sort of message telling you what the issue is.

  • Hello.

    I have problem with resizing the image.

    http://bxk81.youndme.com/...8;w=560&zc=1&h=170

    This is the URL. If you try to open, http://bxk81.youndme.com/.../2011/03/bigbang-tonight.jpg, then it works fine but it says, "file not found /files/2011/03/bigbang-tonight.jpg"

    I created both temp and cache with 777 permission but it is still now working.. Do you know any reason for this?

    Thanks!

  • Great script!
    But I have a problem. It's resizing but cropping the photos, I want it to actually resize it and scale it down.
    Help please? This is the code I'm using

    <img src="/timthumb.php?src=
    &h=100&w=200&zc=1" alt=""/>

    Thanks ALOT in advance!

  • I tried to solve the problem but still, no thumbnails appears in my website. Anyway, my readings still not finish its just step one. hope if i finish learning timthumbs from this blog hope it will take effect on my site. it needs thumbs so so bad!

  • hy, is it possible to have a color profile in images like sRGB? Cause the fallback of mac os for images without profile is to use the monitor profile. if you have a wide gammut monitor the colors look very oversaturated. sRGB colorprofile solves this problem.

    any hints?
    thx&greetz

  • I bought a wordpress theme from rt themes that incorporate Tim Thumb. I am using it on rishriners.com I just updated my server to php 5.2.17 and now the images don't appear. Is this a Tim Thumb issue? Any help will be great.

  • Using the Automotiv theme it's generating thumbnails and images just fine on my local xammp install, but the identical install hosted with bluehost is a no show (file not found error when you right click) - the URLs are identical.

    Versions 1.23 and 1.25 both don't display. I've played with folder and file permissions and it's quite easy to get a 500 internal error for the image when using 777 for the file or the scripts folder. 755 sorts that error but still throws out a file not found on right click.

  • Just out of interest, I just tried uploading this modified version of the file (it's linked to in the first comment) and it's now working:

    [link removed because the content is out of date]

    Maybe that'll help somebody far cleverer than me to figure it out!

  • Hi,
    I'm using timthumb for my website, however images don't load in the main page. I've tried changing permissions, even tried to see it there was something wrong with the theme code, but with no success.

    Here's the link to the website i'm building, it's all about images here and I can't seem to make it work. http://beta.artmania.ro/

    • Profile

      Hi Alexandra - please make sure you are using the latest version of the script.

    • Alexandra, if it still doesn't work with the last version, send me an email (in Romanian) on contact page on my site (click on my name). I have it running on 5 sites and even there were some small problems when I started, in the end I have them all working fine.

  • Actually Alexandra's problem is caused by printing a warning introduces in php 5.1.0:

    Note:
    Since PHP 5.1.0 (when the date/time functions were rewritten), every call to a date/time function will generate a E_NOTICE if the timezone isn't valid, and/or a E_WARNING message if using the system settings or the TZ environment variable.
    (http://php.net/...function.date-default-timezone-set.php)

    You must not use the system default time if you want the warning not to show. In her case a simple
    date_default_timezone_set('Europe/Bucharest');
    added to line 529 fixed the problem.

    I think you should treat this issue in the following releases as it might affect others, too.

    • Profile

      Thanks for the tip - I wasn't aware of this.

      In this case I would have thought the easiest way to stop the errors is to suppress error messages entirely (error_reporting(E_NONE)?

      • True, it might have been easier, but as I think it's there because it's needed in this moment :)

        Just imagine that all people debugging their scripts cannot use timthumb until they completely removed all other php warnings/notices/errors.

        This is why editing the timthumb might be a better solution :)

  • Hi, Binarymoon.

    I'm a new WordPress user .
    Now I'm using a theme which use timthumb to generate a photo-gallery.
    Everything's just fine but I need to edit the size of images which generated by timthumb to suit what I need.

    The problem is :
    I can't find the place of the code who made the thumbnail call in the theme.

    I've searched for lines which look like:
    /scripts/timthumb.php?src=http://..../uploads/image.jpg&w=600&h=400&z=1
    in my index.php and single.php but still I can't find it.

    Any suggestion?
    (Thank you)

  • Hi
    I have a question please;
    Now tha I'm using a template with (Timthumb) (wordpress) it is generating the thumbs fine for new posts, but how can I get it to generate thumbnails for older posts?
    I have arround 350 articles!!!
    Thank for your help

    Ramzi

    • Profile

      Hi Ramzi - theoretically your theme will do the thumbnails for you. If not then you will need to ask the author of the theme to help. I can't help with making the theme find thumbnails.

  • Hey Ben!

    I'm having trouble with this code... i've copied your code straight over and I'm having problems.
    link:
    http://nicholasburge.com.au/img/img.php

    Thanks!

    • Profile

      You are not using TimThumb on your website - so the resizing is not going to work. You also seem to be using a lot of proprietary Internet Explorer filters which is really bad for browser compatability.

  • Thank you! I love this script!
    But is there anyway to change the default width, height, and quality?

  • Hey nice tutorial , i wanted to know how can i use this script in wordpress?? with the post-thumbnail feature?

  • Hi Ben,

    I'd like to use your script. I uploaded the TimThumb meets MCE plugin to my WP and activated it. I found your site because the image resize button in the WP MCE didn't appear/display in the post I am creating. I do have the latest version of WP. The blog's theme is flexsqueeze2.

    You suggest that I use the timthumb.com script at http://timthumb.googlecode.com/svn/trunk/timthumb.php. I do notice that the above script is different (and appears more current) that the script contained in the WP plugins that I uploaded to my blog.

    Could you tell me which script I ought to be using? I also noted that the plugin script doesn't contain a "temp" folder but it does contain a "cache" folder. And, I wonder if the default permissions for these 2 folders are 775 or 777 -- which is it? You did state that this script updates regularly so it's good to signup for updates.

    • Profile

      Hi Leslie - the version on Google code is always the most recent. Always use that one, it has a number of speed improvements and security enhancements that older versions don't

  • Oops! I almost forgot. I want to crop images but again, I'm unsure which of the 2 TimThumb scripts permits me to do this. Cheers to you. :)

  • Hi,
    I hv been experiencing issue with cropping of the photos.
    if you have a look at http://www.tudomudou.com/mashlife/
    the images in the sidebar are all cropped in unequal proportion.

    Please let me know how can this be fixed?

  • Excuse me, I would like to use in windows iis in timthumb.php
    zh-bs.com can not use

  • http://zh-bs.com/....gif&w=160&h=140&zc=1

    you look? it can not show pictures, but can generate images in the cache, permissions set up everyone, the picture shows pork on a skewer
    Website is zh-bs.com

  • Hi guys, I had a problem because to use the function strtotime() needs to be defined the timezone.

    If anybody gets the same problem only need to define the timezone at the begining of the php file where save the code of the library.

    date_default_timezone_set('America/Guatemala');

    Only for information prouposes I use lampp server on Fedora 15, maybe the configuration by default of the server can throw this error.

  • Hi

    Do you think that TimThumb is a solution when dealing with heavy load websites? Does it affect the speed-load and by any chance create a bottleneck?

    Thanks

    • Profile

      Any dynamic content will add more processing requirements and load time to a website. In this case it will be slowest when the cache files have not been created, and the user has not visited the page.

      I can't say how it will affect your website though. The only thing I can say is to make sure you keep up to date with TimThumb versions. I update it quite regularly and always try to speed it up, and make it more secure.

  • Hi Ben,
    I am having issues with SOME thumbnails. I created a test page displaying original and thumbnail side by side. You can see the thumbnail on line 1 is broken.

    Go here: http://thasneen.com/cooking/thumb-test.php

    Any idea? I have been trying to figure this out for the last couple days with no success.

    ps:
    On my website the thumbnails stopped working for all posts from the 1st week of Jan 2011 and all posts BEFORE that. The newer posts are all fine.
    http://www.thasneen.com/cooking/2011/01/

  • i upgraded to timthumb version 2.0 and still no go. the images are there in my uploads directory but all thumbnails are failing for posts older than Jan 2011.

  • I don't seem to see whether your program can deal with both vertical and horizontal images to retain their aspect. I have a store and there are currently 1500 thumbs to be loaded, some have been shot vertically - for clocks, while others were shot horizontally for tables and other furniture. Is this the right program for me?

  • Hi Ben, I'm not sure to understand how TimThumb works after merging WordThumb. Do I always need a cache directory with CHMOD 777. And the temp directory for the external files? I see you can leave the value for cache directory blank. What is the difference?

    Thank you

    • Profile

      If you leave the cache directory blank then TimThumb will use the server temp directory. This is not always usable (based upon server configurations) so the cache directory may sometimes be required.

  • Hi,

    I hope you can help! I've been using timthumb as part of a Theme purchase and recently upgraded the theme and none of the images are now showing on the posts, although they are there and they open up quite correctly when clicked.

    I changed the timthimb.php file according to the google code link you supplied and I had to manually add in a cache & temp file to my scripts folder. I've messed around with 775 and 777 for these but still the images aren't displaying.

    Have you got any suggestions how to get it working? Do I need some sort of cacheing script?

    Thanks!
    Sam

  • Hi, I am having the same situation as Sammiej in the post above. On a client's site, the thumbnails no longer show but he says they used to. The site is http://www.brainpcgames.com. I found this post about the timthumb 2.0 update as related to the theme http://wparcade.com/blog/ and followed the instructions to replace the timthumb.php file and add the index.php and htaccess to the cache folder. Also tried all of the permissions changes suggested, and made sure that no directories above the timthumb file had 777 permissions. Is there something else I can look for?

    Thanks a ton!

  • Hello there,
    same problem here as Ken S and Sammiej
    any new about it?
    thank you!:)

  • Hi,

    I have a problem. I buy a template from Theme Forest which use the timthumb script. There is, like described, two folders (cache and temp) in the same folder than the timthumb.php file. These have the 777 permissions.

    But in front end it doesn't work. When I lokk with firebug, it indicates "Failed to load the given URL". The image is well in the temp folder but not in the cache folder.

    Could you help me because the support of Theme Forest doesn't.

    Thank for advance

    Papou

  • Hi,

    I can't seem to get the thumbnails to show up in my slider in a WP theme called Milan from Siiimple.

    I've set the code to allow external sides, tried different permissions, and yet it never loads the images:

    http://www.sublimethings.com/beings/?p=351

    Would you mind taking a look at the code?

  • Home does not show my picture! I do not know what the reason, many methods are used! Is not! Help me look at it? I ie315.com! Thank you!

  • Hi!

    I check around your site to look what's my problem but i'm still not able to make my blog work properly with WP and timthumb.php. You can take a look at latexpirate (dot) com and see that we cannot see the image at the good place. As soon as I put the timthumb.php code I receive a x icon. All my stuff are 777 right now and I also try it to 775 and 755. I really need help please. Thanks!

  • @Bigmath, Hi, try making your folder cache to 777 and thumbs to 777. I hope this works.

  • I've got the same exact problem as Kristian. Images are cached, but not not displayed.

    http://sawln.org/category/blog-media/

  • I have purchased a theme that uses the TimThumb script in the opening slider. I am experiencing issues with the images not loading. Refreshing the page produces similar results. It is not always the same image. I have tried changing the permissions from 755 to 777 in both the cache and temp folders in the php file included with the theme. This did not help, and my host recommended that I use 755, so I changed it back.

    The images are stored in a folder on the public_html root directory on my server entitled /images I have tried changing the jpeg file size as well as made sure that they were not loading progressively. This also did not help.

    The theme uses a user interface where I can enter the image URL. I have tried both relative and absolute image paths.

    Perhaps, you could take a look at ipa-connect.com ~ any help would be greatly appreciated. I am at a loss.

  • I am unable to get it work Under IIS 5, I always get "HTTP Error 400 - Request is badly formed. Internet Information Services (IIS)", you can see it on "http://www.mundoplano.com/public/timthumb.php" and the info "http://www.mundoplano.com/public/info.php"

    Thanks in advance for the support

    Alex

  • If i wish to specify the width alone and height as auto means, how can i specify that in the img src? Please give the code with an example. Thanks for your product. I really like timthumb which help us in resizing the images

  • Hi, great script but i need to use timthumb like this:
    Ex: thimthumb.php?src=getImage.php?imageID=122
    or: thimthumb.php?src=getImage.php%3FimageID%3D122

    something like that, but it gives this error: Could not find the internal image you specified.

    Thanks in advance... keep up ^_^

    • Profile

      That's not going to work. The only possible way to do this would be to make the url absolute (include the domain at the start) and to wrap the url in url_encode so that the parameters don't confuse the script.

  • thank you for such a great script.
    I was wondering if it causes server overload if i use this script massively in my website.
    For ex: I use this script to generate around 50 - 60 image thumbs in a single web page.

    Have you experimented in this?

    • Profile

      Anything can overload the server if you abuse it :)

      That said - I have tried to optimise it as much as possible and with browser caching and whatnot it shouldn't be too bad after the initial image creation.

  • You're product it,s great.

    I have a error when i want put some parameters (ex: for change the height &h=150 )

    My code
    images/Condo200-116-1.jpg
    TimThumb/timthumb.php?src=images/Condo200-116-1.jpg&h=150

    The version of my script VERSION', '2.8.3

    Thanks

  • Thank you for making this great script. Is it possible to make a mini-timthumb that only has the basic resizing features?

    I have a website with about 100k visitors and 500k pageviews. I have seen this script go from 18k to 50k, without features I never use.

    Currently timthumb is consuming around 35GB of traffic every month and it would be great if there would be a 20k mini-timthumb with the basic features.

    • Profile

      Hi Lisa - the size of the script shouldn't matter too much since it doesn't actually get downloaded. I am certainly considering ways to simplify the code but I don't plan to make a mini version. If someone wants to fork it and make a simpler version they are more than welcome to.

  • Ok, I'm using your code to create a thumbnail of an image, but when the image is smaller than the expected thumbnail, it is ENLARGED, what I do not want. How can I say to your code "DO NOT RESIZE" if width is less than a certain threshold? Thank you in advance.

  • Hi, My error log is filling with these out of memory errors:

    [29-Dec-2011 18:18:25] PHP Fatal error: Out of memory (allocated 262144) (tried to allocate 77824 bytes) in /home/ikwilfil/public_html/wp-content/themes/mad/lib/scripts/timthumb.php on line 585
    [29-Dec-2011 18:18:28] PHP Fatal error: Out of memory (allocated 262144) (tried to allocate 77824 bytes) in /home/ikwilfil/public_html/wp-content/themes/mad/lib/scripts/timthumb.php on line 585

    I have already edited the memory limit in timthumb but still get the errors, i am using v2.8.5. please help

    regards,

    jaapo

  • i resize from 200x300 to 100x150 is that too large? i got about 1000 thumbnails that way.

  • Hi,

    I am trying to use timthumb on one of my websites which is on a shared webserver with virtual hosts in apache httpd.conf (windows).

    The issue is that the document root retrieved by

    $docRoot = @$_SERVER['DOCUMENT_ROOT'];
    if (defined('LOCAL_FILE_BASE_DIRECTORY')) {
    $docRoot = LOCAL_FILE_BASE_DIRECTORY;
    }

    Seem to not work.

    If i disable virtual hosting timthumb works instantly on local images stored on the webserver, but with virtual hosting enabled it seems timthumb cannot find the proper document root.

    Is there anyway i can manually insert my document root instead of having php trying to fetch it through command?

    Thanks.

    • Profile

      If you add a file called timthumb-config.php in the same directory as timthumb.php then you can override settings like this. In this case there's an override called LOCAL_FILE_BASE_DIRECTORY so if you set a new define in timthumb-config with the correct value then hopefully it will work.

  • My issues were deeper and more advanced then i though, i did some debugging and found the issue.

    The issue i have is that my images are served over htaccess which rewrites the original paths, however those requests are only rewritten if its coming from http.

    If i put the images on the same domain as the wordpress the timthumb script will try to use the local function to access the images resulting in them not being found.

    What i need to do is to somehow rewrite the local function to work exactly like the external function.

    I made a ticket for my issue here:

    http://code.google.com/...roupby=&sort=&id=315

    Took awhile for me to figure this out, sorry for the confusion.

  • I fixed my issue by modifying the script at line 229:

    remove $this->src = preg_replace('/https?:\/\/(?:www\.)?' . $this->myHost . '/i', '',$this->src);

    and it will treat same urls as external.

    I have a follow up question, how can i make sure that the script NEVER clears the cache and NEVER looks for a new thumbnail once the thumbnail has been generated?

    I set

    if(! defined('FILE_CACHE_TIME_BETWEEN_CLEANS')) define ('FILE_CACHE_TIME_BETWEEN_CLEANS', -1);

    if(! defined('FILE_CACHE_MAX_FILE_AGE') ) define ('FILE_CACHE_MAX_FILE_AGE', -1); // How old does a file have to be to be deleted from the cache

    if(! defined('BROWSER_CACHE_MAX_AGE') ) define ('BROWSER_CACHE_MAX_AGE', 8640000000000000000000000);

    But it still feels like its sometimes regenerating the thumbnail.

    Thanks.

  • So I've been playing with this all day and am ready to tear my hair out. I've installed timthumb and have set my cache and temp folders (which are residing, along with the timthumb.php script in wp-content/themes/my-theme) to 775 - I originally had them at 777 but still it wasn't working.

    I have a search function that spits back a selection of posts and I'm trying to get the thumbnail to show up for the post using the following code on my category page (which is the search result page)

    <a href="" rel="shadowbox;width=930;"><img src="/timthumb.php?src=&w=206&h=104&zc=1">

    My result page is coming back fine - but there are no thumbnails. When I check the cache folder, there are no thumbnails in there, nothing in the temp folder either. What am I doing wrong?

    Is there a secret to adding the images in the WordPress post, have I completely screwed up my code. Please help me I'm desperate.

  • Ahh okay the code doesn't come out right there. The code should read (excuse the php code not being written correctly - I can't think of any other way to write the code in here properly - on my files the code is bang on target):

    <img src="/timthumb.php?src=&w=206&h=104&zc=1">.

    • Profile

      Hi TIna - if you're using the_permalink then you're setting the image source to be the url of the post, and not the url of the thumbnail. If you can get the post thumbnail url and use that instead it should start working.

  • Trying one last time with the code:

    <a href="" rel="shadowbox;width=930;"><img src="/timthumb.php?src=&w=206&h=104&zc=1">

  • I have tried everything to get TimThumb to work with the Seventeen WordPress Theme from Alex Pascal. Have checked the directories temp and cache and their permissions. None of the graphics scales.

    Not sure what to so next :0

    Any help will be appreciated

    Regards
    jeffrey

  • I am using 1and1 hosting and keep receiving this error "URL file-access is disabled in the server configuration in..". I read somewhere it's because the new PHP 5 has by default the command "allow_url_fopen" turned OFF.

    Is their a hack or anyway still possible to use TimThumb?

  • Hi Ben.

    My timthumb.php could not show any images on the website, caused reason probably the webserver ( but system admins would not repair.. :( ).

    sys admin says: "your script going to deep ( up ? ), where you do not have permission at all...".
    " File(/servers/httpd/htdocs/ujlap/wp-content/uploads/2011/09/image-127.jpg) is not within the allowed path(s) "

    must be like this: "/USER/autouveg-soos/autouvegsoos.hu/www/ujlap/wp-content/uploads/2011/09/url9.jpg "

    theme developer says: " problem with server , ask sys admins to fix it.."

    the website: " http://www.autouvegsoos.hu/ujlap/car-listing/ "

    ERROR :
    " http://www.autouvegsoos.hu/...h=180&zc=1&q=100 "

    output:

    "Warning: realpath() [function.realpath]: open_basedir restriction in effect. File(/servers/httpd/htdocs) is not within the allowed path(s): (/USER/autouveg-soos/:/servers/php/lib/php:/tmp/phpupload:/tmp/phpsession) in /USER/autouveg-soos/autouvegsoos.hu/www/ujlap/wp-content/themes/radial-theme/timthumb.php on line 815

    Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/servers/httpd/htdocs/ujlap/wp-content/uploads/2011/09/image-127.jpg) is not within the allowed path(s): (/USER/autouveg-soos/:/servers/php/lib/php:/tmp/phpupload:/tmp/phpsession) in /USER/autouveg-soos/autouvegsoos.hu/www/ujlap/wp-content/themes/radial-theme/timthumb.php on line 827

    Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/servers/httpd/htdocs/ujlap/wp-content/uploads/2011/09/image-127.jpg) is not within the allowed path(s): (/USER/autouveg-soos/:/servers/php/lib/php:/tmp/phpupload:/tmp/phpsession) in /USER/autouveg-soos/autouvegsoos.hu/www/ujlap/wp-content/themes/radial-theme/timthumb.php on line 853

    How could i change the timthumb.php " $_SERVER " to the URL path or change only the relative path to wp-uploads folder ?

    I uploaded an other server, where works like a charm, but client would not leave the above mentioned host provider.

    other: "http:/www.unit45host.com/virtungolas " pictures show up, without problems, and modification.

    Thank you for help.

    Zoltan

Leave a Reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

About me

About BenMy name is Ben Gillbanks. I'm a lover of Video Games, WordPress, Web Development and everything in between.

I have been working on the internet since 1998, and working with computers even longer. I am a hardcore Nintendo fanboy and have owned most of their consoles at one stage or another.

Read more about me on my about page.


Follow Me


Random Link-outs

The Binary Network links to all my websites
bengillbanks.co.uk - Ben Gillbanks

Ben Gillbanks

All my websites under 1 roof, the easiest way to find out what I do

Pro Theme Design - premium WordPress themes

Pro Theme Design

Premium WordPress themes by web design pros (erm... that includes me)

Binary Joy - gaming news and reviews

Binary Joy

Gaming news and reviews

Binary Sun - play free online games

Binary Sun

Play and download free and paid games (many made by me)

Gaming Angel - download and play games online

Gaming Angel

Stacks of shareware games, free to try and cheap to buy