Ben
Ben is a lifelong Nintendo fan who likes to build websites, and make video games. He buys way too much Lego.
WordPress and Games
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.
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.
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.
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.
The parameters below are the main ones used. With these you can resize almost anything.
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.
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:
http://www.everify.com/resources/?p=1309
Its the testing link there under the red written “testing”
I’d be glad if you gave me a small hint.
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.
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!
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.
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.
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.
David, could you please help us in solving this problem ? Thanks!
Hey david, can you help me.
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.
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 🙂
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!
Replaced timthumb by the_post_thumbnail, itmakes as well as timthumb and without the risk have a day, a new fault of security as timthumb!
http://stackoverflow.com/questions/9526351/how-can-i-replace-timthumb-with-wordpress-native-image-tools
It’s an option for sure 🙂
Worked like a charm…thanks!
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 “
Howdy,
Installed Respo theme and having all sorts of image glitches – http://needleandspindle.com/ – cache is 775 – what is the basic error I have overlooked? thanks!
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.
Can you please help I don’t have any idea what to do any more
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.
thanks for the comment, please feel free to suggest a fix.
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
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?
Hmmm… my last message didn’t seem to post completely. Let me see if I can simplify it.
Does not work:
http://jennacomm.com/wp-content/themes/nevo/includes/timthumb.php?src=http://jennacomm.com/wp-content/uploads/2012/12/413362_254703827982345_808989654_o1.jpg&w=83&h=83zc=1&q=100
Works:
http://jennacomm.com/wp-content/themes/nevo/includes/timthumb.php?src=/wp-content/uploads/2012/12/413362_254703827982345_808989654_o1.jpg&w=83&h=83zc=1&q=100
The only difference is ‘http://jennacomm.com’ in the src.
Any ideas?
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
Hello, I used Timthumb in theme CONSULTANT I bought.
The thumbs don’t show up and I’ve tried and reviwed all tips in this page.
Can you plese look at it?
http://www.ensinarmelhor.com
Thank you
Hi – you can view my TimThumb support rates here: http://www.binarymoon.co.uk/projects/timthumb/timthumb-technical-support/
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 🙂
You need to edit your theme so that it doesn’t try to embed timthumb if there’s no image assigned to the post.
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?
Cheers,
Kat 🙂
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,
Mark.
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?
Thanks
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:
thumb.php?src=images/image.jpg&w=300&h=250&q=80
With this regex:
thumb/300/250/80/images/image.jpg
thumb////
you can use thumb or image.
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…….
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
Regards-
Dhruba Jyoti Deka
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?
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.
Got it working
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
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.