Background
The script was written by Tim McDaniels as a way to achieve the core functionality of phpthumb while using half the code. Ben then added PNG and GIF support, plus improved speed and caching.
I wish we had a cooler name for the project, but ‘timthumb.php’ was the first filename I used during testing and it somehow stuck.
How do I use it?
Simply copy the source code into a new document called ‘timthumb.php’, place it in a folder on your site (ex: /scripts/) and call the image like this:
<img src="/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1" alt="" />
Some important things to note:
- TimThumb requires the GD library, which is available on any host sever with PHP 4.3+ installed.
- Once installed and in-use, TimThumb will automatically create a /cache/ subfolder with proper write-permissions. If your host server doesn’t allow this by default, be sure to manually change the /cache/ folder permissions to 777.
- In addition, make sure the folder which contains TimThumb is set to 777.
- As in the example, use absolute paths for your script and images
- To really speed things up and make use of the advanced caching checks added to the script, copy these rules to your .htaccess file.
TimThumb allows the following parameters:
- w: width
- h: height
- zc: zoom crop (0 or 1)
- q: quality (default is 75 and max is 100)
Feedback
If you’re a developer with specific coding improvements to suggest, please get in touch with Ben. If you’re a user, leave a comment about what features you’d like to see.
Popularity: 6% [?]
Thanks for releasing this! I shall give this a try soon. Seems pretty great.
--April 3, 2008 @ 1:37 amThis does indeed look very handy. I think I already have a use for it :)
One feature I’d like (it might already do this, I haven’t tried) is to just specify, say, a width, and have the script take care of maintaining the aspect ratio. So if I had an image that was 200px wide and 100px high, and all I used in the url was w=100, the image would automatically be scaled to 100px by 50px.
--April 3, 2008 @ 3:11 amScratch that: I’ve just tested this on a 290 x 236 pixel image. I used w=145 in the TimThumb url, and the resulting image had a height of 118 pixels.
Good stuff!
Thanks for sharing this Darren.
--April 3, 2008 @ 3:50 amVery handy. Thanks for sharing this.
--April 3, 2008 @ 1:58 pmThanks for releasing this Darren. I’ve been using a similar script i wrote myself, which was customised for WordPress, but tim thumb seems far more complete (I was relying on files that had already passed through WordPress, thus having WordPress generated thumbnails! Pretty horrible).
Thanks again.
--April 4, 2008 @ 8:08 pmreally super code to crop the image in different size. great work thank a lot. i think it’s more useful code for all of php programmers. once again i thank u lot
--April 5, 2008 @ 1:13 amCool, as always, and the timing couldn’t be better. I just realized that it seems that WP 2.5 doesn’t create thumbnail images, it just resizes an image if you say you want a thumbnail. That is a problem with a theme that I’m using, so this may solve the problem.
--April 6, 2008 @ 6:54 amNice! I was just modifying the Unstandard theme, wishing there was an auto thumbnail generation script - and here it is. I just built it in and it works fine! About the advanced caching checks I could put in the htaccess though, can I just use those without it interfering with my Wordpress setup?
--April 6, 2008 @ 11:44 pmThe htaccess stuff shouldn’t interfere with other WP issues. I’ve got it written into a couple htaccess files on my sites and haven’t noticed any weirdness.
--April 6, 2008 @ 11:54 pmIs this wonderful script working with JS libraries like Lightbox ( or a derivative ) and if not, how hard would it be to incorporate this for an absolute PHP noob ?
--April 8, 2008 @ 10:20 amCould you please demonstrate how & where to hardlink the Lightbox code in your PHP source ?
Being able to display nice & easy thumbnails is all good & well, but if the originals are not easily accessible for display, why bother with them in the first place …
@Peter: if you’ve already used Lightbox, etc, you can use it in the same way, just construct the image URL in the way I demonstrated above (”/images/whatever.jpg&h=150&w=150&zc=1″)
--April 8, 2008 @ 11:16 amThank you for your prompt & helpful response !
--April 8, 2008 @ 12:50 pmI realise this is not a WP plugin, but it now looks like a very neat solution to the WP 2.5 thumbnail scaling issue, mentioned here earlier. I find that almost all of the existing WP plugins for image handling badly suffer from the prevalent tendency of ‘featuritis’. I don’t need a Photoshop-cum-FTP-cum-Ajax slideshow plugin to give me a decent thumbnail in a post …
TimThumb may well fit my need perfectly, so thank you for making it available !
Great script. Though, Id rather use my batch resizer as much as possible and avoids GD if I can. But the script would come in handy one time I guess :) Thanks
--April 11, 2008 @ 3:01 amJust a quick suggestion about using mod_rewrite to improve the path reference to a resized image, sometning similat to this -
http://mrphp.com.au/node/1805
--April 12, 2008 @ 5:52 pmGreat script!
--April 12, 2008 @ 6:38 pmAdding support for resizing remote images would make it even better.. :)
Very nice idea, I could really use something like this.
Three unfortunate things I’d love to see “fixed”:
1. Unfortunately it enlarges images smaller then the h x w size bounding, instead of leaving them in their original size.
2. Unfortunately it doesn’t maintain the original correct aspect ratios images. Stretch, ugghh, no thanks, how about maintain the aspect ratio and resize within the w x h bounds.
3. Unfortunately it doesn’t maintain png transparency. Oh white, you are nice, but not in big blocks around images that used to have transparency.
If those three items were fixed this script would be absolutely perfect.
Especially if crop did an aspect correct zoom then crop.
I’d be happy to work with you to provide examples of the above three issues.
--April 14, 2008 @ 3:38 amThanks again for the fabulous contribution.
im getting an error saying
“Invalid src mime type: unknown”
what does this mean????
--April 28, 2008 @ 9:14 amUnfortunatly I get the same error:
Warning: shell_exec() has been disabled for security reasons in
../scripts/timthumb.php on line 186
Invalid src mime type: unknown
How can I fix this?
--May 3, 2008 @ 2:42 pmCan you guys post live examples of your errors? Also, have you confirmed with your host that GD library is installed?
--May 3, 2008 @ 4:41 pmGuys, go ahead and grab the latest copy from the Google Code site. It should fix any mime type issues.
--May 4, 2008 @ 12:50 pmMhm,
--May 13, 2008 @ 8:49 amimage is uploaded through custom-field and there, but the image doesnt pop up, only the alt tag.
Checked the paths- all right. Code also ok as is the gd libary for php.
Idea what could have happened?
Cheers, Os.
I’ve got it working! :D :D
I found another version of TimThumb @ http://timthumb.googlecode.com/svn/trunk/timthumb.php
Thanx for your time, support and the script!
--May 16, 2008 @ 7:20 pm