The custom image-resize script created for Mimbo Pro is now available as an open-source project! It’s already being used by a handful of other theme designers and I look forward to seeing what other folks do with it.
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.
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:
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)
Support
Please visit the dicussion forums»
1:37 am
Thanks for releasing this! I shall give this a try soon. Seems pretty great.
3:11 am
This 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.
3:50 am
Scratch 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.
1:58 pm
Very handy. Thanks for sharing this.
8:08 pm
Thanks 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.
1:13 am
really 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
6:54 am
Cool, 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.
11:44 pm
Nice! 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?
11:54 pm
The 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.
10:20 am
Is 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 ?
Could 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 …
11:16 am
@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″)
12:50 pm
Thank you for your prompt & helpful response !
I 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 !
3:01 am
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
5:52 pm
Just 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
6:38 pm
Great script!
Adding support for resizing remote images would make it even better.. :)
3:38 am
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.
Thanks again for the fabulous contribution.
9:14 am
im getting an error saying
“Invalid src mime type: unknown”
what does this mean????
2:42 pm
Unfortunatly 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?
4:41 pm
Can you guys post live examples of your errors? Also, have you confirmed with your host that GD library is installed?
12:50 pm
Guys, go ahead and grab the latest copy from the Google Code site. It should fix any mime type issues.