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 scoped out by me and originally written by Tim McDaniels as a way to achieve the core functionality of phpthumb while using half the code. Ben Gillbanks then added PNG and GIF support, plus improved speed and caching.
Ben now handles TimThumb’s development and has written a series of great articles and additional documentation.
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
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»
Follow me on Twitter
4:53 pm
@Darren #1 : Yes the script was built to do that for bandwidth restrictions, however I have reprogrammed my timthumb.php to allow remote access as we are allowed to from the company where we will be grabbing the images from…
@Darren #2 : I think I know what the issue is I’m getting a PHPINFO report right now on it on that server, but I think it might be because the GD library is not installed on php. Anyways I’m not sure yet and I sent you the URLs by email if you want to check it out.
-Casey
5:00 pm
@ Darren : I was wrong, GD is enabled on both servers. I’m lost on this one.
8:04 pm
I encountered the same problem right after firefox updated to 2.0.0.12.
9:30 am
The image is not showing on?? I dunno why!!
My hosting has support on GD, PHP5
And im done changing the permission(777) on some of the required folders.
Still the image is not showing.. =(
Darren can u help me out man? I can give u access on my site if it is required
Heres my site: http://wptest.david-cook.info/
11:05 am
@thewebguy: I have found using absolute urls to be a problem and I have resorted to relative url’s. Maybe this is not ideal for you? But give it a try.
2:43 pm
@thewebguy:
in regards to timthumb.php — Ooops, I cannot find you the page you are looking for. Error 404
3:48 am
Hello.
Darren, I have the same problem as Jacobo, used two hosting for dividing the width of banda and my web traffic. In one case, the images stored there and in another files blog. Is not there a way to adapt the code and to be able to put the url of the other hosting a TimThumb? I think there must be some way and that we could help.
Thank you for everything.
5:45 am
Hello,
I have just one problem with this script. Before installing this script I was using the absolute path to the image for the custom field (http://mysite/wp-content…).
I don’t want to modify all the custom fields. What do I have to modify to make this script work?
5:40 pm
Thankss….
10:41 am
Can I change some code if i want to use external picture?
And How can I change it?
Thanks
2:22 am
Your code has a bug
If the header ( $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ] ) isn’t set by the server and you have error reporting set to on, the script screws the JPEG http header and the image doesn’t render.
Need to put:
$gmdate_mod = gmdate( ‘D, d M Y H:i:s’, filemtime( $cache_file ) );
Before
if( isset( $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ] ) ) {
6:17 am
@Aree
I actually had this same issue and fixed it myself.
Although on a couple different servers I tested it did work
And then on some others it didn’t.
7:55 pm
Hi,
Great script! I’ve had no problems using the script to create my thumbnails but to take my design forward I want to have the thumbnails it creates watermarked. What code will let me do this and where do I insert it because everything I try breaks the code or just shows me the cached image this script already generates. If it helps all my images are jpg.
Thanks
1:24 pm
What would be cool is if you could call up a file image resizes selection tool similar to the one on Wordpress Theme Headers.
3:47 pm
Я вам очень благодарен, мне понравилоÑÑŒ.
5:30 am
I didnt get TimThumb to work with GIF images. Don’t know why, tried a lot of adjusting but didn’t work out.
I’ve found SmartImage Reiszer (also PHP) which works just as easy as TimThumb, but only this one supports GIF images.
http://shiftingpixel.com/2008/03/03/smart-image-resizer/
If anyone knows how to get TimThumb to work with GIF images, please post it. I’ll read it and switch back to TimThumb.
4:15 pm
Bas, try changing line 170 from
imagegif( $image_resized, $cache_file_name);
to
imagegif( $image_resized, $cache_file_name, ceil( $quality / 10 ));
4:18 am
how can i adjust the output file size? i need the file size to be in the minimum.
11:09 pm
Is there a way to make the script or GDLib have less of a color shift from the original to the processed version? Compare…
Original:
http://www.darrenhoyt.com/timthumb/images/sample.jpg
Processed – Same size, High Quality
http://www.darrenhoyt.com/timthumb//scripts/timthumb.php?src=/timthumb/images/sample.jpg&h=300&w=400&q=100&zc=1
Thanks – great script.
11:20 pm
I think you’re seeing a difference in compression, not color. The compression is set by default to 75%, but you can change it – see line #13 at the top of timthumb.php.
11:44 pm
Thx for the reply Darren, however I did specify q=100 in my link,
9:27 am
Hey I have an error on both local and on my php5 webserver.
Warning: Cannot modify header information – headers already sent by (output started at /home/beextraordinary.nl/www/test/scripts/timthumb.php:2) in /home/beextraordinary.nl/www/test/scripts/timthumb.php on line 279
Also the picture is shown in bineare code not very usefull. I juse the following URL http://www.beextraordinary.nl/test/scripts/timthumb.php?src=http://www.beextraordinary.nl/test/images/test.jpg&w=150&h=200
Anyone any idea’s?
6:00 am
Круто, ÑпаÑибо! ;)
1:03 pm
Hey Darren,
First off, thanks a lot for this script, it looks amazing. However, I’m having a problem with it. Every image I send it, it says ‘file not found’. I made sure the cache folder was 0777 and checked that the image was accessible.
http://sheaallen.com/wp-content/themes/arthemia/scripts/timthumb.php?src=http://sheaallen.com/files/2008/08/143014w_sm.gif&w=300&h=275&zc=1&q=100
Am I doing something wrong? I appreciate your help, thanks so much again.
-Shea
6:10 am
Thanks a ton Darren!!! GD library was screwing me down. But you helped me fix that out and use timthumb.php Thanks a lot once again.
7:48 am
Is there any way to use mod_rewrite with timthumb to rewrite more friendly URLs? e.g. http://domain.com/scripts/timthumb/animage.jpg?
3:31 pm
unfortunately the timthump.php script doesn’t work anymore, after an update to wp 2.6.1. Does anybody have an idea why?
regards, Andy
6:52 pm
This looks like a great plugin and an alternative to phpthumb. However, some things are missing.. It seems it doesn’t enlarge images over the original size. I could be wrong though, but I can’t seem to get images to go over 150 pixels – which is the original dimensions (length & width).
8:26 pm
I came across this in use on the Arthemia theme, am going to implement it in a couple of my sites that have been causing me painful updates as they required stuffing around with custom fields for every article.
Awesome work!
12:55 pm
I was testing in Safari 3.1.2 and noticed that the thumbs were not generating. Instead the alt tag was printed with the “?” icon. When I refreshed, the images appeared. I clear the cache, link back to the page using timthumb and the same broken image occurs. I refresh, and there the images are again. Strange. It works in IE and FF.
A note: I am using the orderedlist version of jQuery FancyZoom, but I don’t think that is causing the issue, since it will zoom from the thumb with the same broken image.
Weird huh?
Rich
3:50 pm
Hmm, just tested in Safari 3 and can’t duplicate the error. Are you definitely using the most recent version? I’m not sure it’s related to the script, but could be wrong.
8:32 pm
This is used in the mimbo pro theme I use (im sure your familiar with it ;D), and I just added it to the blog that i use your Agregado theme in. Works like a charm on the latest post area! Thanks :)
12:18 am
@lori: very cool!
11:34 am
Hi there. I installed wordpress 2.6.1 and then installed the Arthemia theme.
Problem is that when I forget to post an image at the end of my post, it shows a blank thumbnail in the random posts. Also I can only get the thumbnails to work if I add a custom thumbnail after every post. This is quite time consuming.
To top it off I had to select the option that the theme uses first image, so it grabs thumbnails off the first image in the post. But in the features section it also displays a blank thumbnail unless I add the custom part in.
I am getting frustrated as I have sat hours working to add thumbnails to posts.
Also the blank thumbnails point to: Invalid src mime type:
4:58 pm
@Sarah: none of that is a symptom of the thumb script, though, which works as it should on themes like Mimbo Pro. If you’re having problems with how the script is implemented, I’d suggest contacting the theme author.
4:08 am
I’m having problems with the script when I generate images with just the width specified, e.g:
It was working fine for me, i.e. setting the width to 140px and making the height of the thumbnail proportional to the original image.
Now, that’s stopped working though, and it is giving all of these images a fixed height of 100px.
Any thoughts?
3:54 pm
I can’t get it to work, I’m going crazy, i have configured the .htaccess and followed everything I’ve read, here’s my html:
It is actually creating the images and saving them in the cache folder, but all I see is the alt text shown. And when I just put the image src in the address bar I get the following error:
The image “http://localhost/scripts/timthumb.php?src=/imagenes/interganga.png&w=120&zc=0&q=100†cannot be displayed, because it contains errors.
3:56 pm
HTML:
\
2:14 am
the image created in cache folder but did not shown up in the browsers :-ss
10:28 am
Hi Darren,
Firstly congratulations on a great script – I have just replaced the post-thumb wordpress plugin with it.
One small problem I have is that the alt title is shown instead of an image when there is a video or flash embedded in the post.
I just wondered if there is anyway I could amend the code to stop this happening please?
The alternative would be for me to prepend a thumbnail on such posts or remove the allt.
Many thanks and best regards,
Michael
4:10 pm
Hi Darren,
I have figured out what is happening – sorry I’m not a Php expert::-)
I am calling your file from a wordpress template, most of my posts have images but some older ones don’t and they are calling just src=”&w=140&h=120&zc=0″ and getting your “no image specified” error.
Is there any easy way in your code that I could redirect such errors to a default image please?
Many thanks again,
Michael
7:28 am
I was having a problem with the timthumb code failing W3C validation.
The fix is simple though:
replace the ‘&’ in the invocation of timthumb with &
i.e. instead of:
use:
<img src=”/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1″ alt=”" />
et voila… your code will now pass W3C validation… well, at least where it uses timthumb it will!
Thanks for the script Darren
7:35 am
darn… it processed the code in my comment:
It should say:
use:
and your code will validate
1:11 pm
Is there anyway to get the script to return a proportionately sized image?
i.e. if I specify just the width, have it automatically calculate the thumbnail height in proportion to the original image.
If I try just setting one dimension parameter, i.e. w=140, it fixes the other dimension at 100px.
Thanks,
Roger
11:31 am
@roger
I was able to get that to work by using 100% for the other measurement. It appears to do what I want, but the code is no longer xHtml clean :(
image.jpg&w=450&h="100%"&zc=0Maybe Ben has a fix?
12:54 am
I think I have it…
<img src="/scripts/timthumb.php?src=/&w='465'&h='0'&zc=0" alt="" />Seems to validate and still return the proper proportionate opposite dimension for the image. Let me know how it works.
11:18 pm
Nice, I may want to use this some day. :)
1:33 pm
This works great – but can it enlarge images bigger than the source? This is a needed addition for myself and was wondering if there is support for it?
10:36 pm
@Danny: unfortunately, no script can enlarge an image and preserve the quality. In general, images should not be stretched.
4:30 am
Hello Darren,
I use this script on a CMS system to dynamically resize images to fit a particular width. In regards to the timthumb – what I meant was, if I had a source image, is it not possible to dynamically enlarge it based upon the parameters I set? I do recall having this ability with phpthumb, though I could be wrong in that regard. I acknowledge that preservation of quality would be impossible – but just enlarging the image – period would suffice.
Appreciate your insight on this mate!