Blog

TimThumb PHP Script Released

The custom image-resize script (TimThumb) 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.

View Source Code | Live Demo

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.

Note: current Mimbo Pro users can download the script now and overwrite their existing /scripts/timthumb.php file. You should notice an obvious speed difference. There will also be a newsletter sent soon linking to the script and some other enhancements.

Popularity: 6% [?]

40 Responses »

  1. Aditya said:

    Thanks for releasing this! I shall give this a try soon. Seems pretty great.

    --April 3, 2008 @ 1:37 am
  2. Dan said:

    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.

    --April 3, 2008 @ 3:11 am
  3. Dan said:

    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.

    --April 3, 2008 @ 3:50 am
  4. Kevin said:

    Very handy. Thanks for sharing this.

    --April 3, 2008 @ 1:58 pm
  5. Simon said:

    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.

    --April 4, 2008 @ 8:08 pm
  6. shan said:

    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

    --April 5, 2008 @ 1:13 am
  7. Miriam said:

    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.

    --April 6, 2008 @ 6:54 am
  8. Guy said:

    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?

    --April 6, 2008 @ 11:44 pm
  9. Darren said:

    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.

    --April 6, 2008 @ 11:54 pm
  10. Peter said:

    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 …

    --April 8, 2008 @ 10:20 am
  11. Darren said:

    @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 am
  12. Peter said:

    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 !

    --April 8, 2008 @ 12:50 pm
  13. fedmich said:

    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 am
  14. sal said:

    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

    --April 12, 2008 @ 5:52 pm
  15. Ed said:

    Great script!
    Adding support for resizing remote images would make it even better.. :)

    --April 12, 2008 @ 6:38 pm
  16. Josh said:

    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.

    --April 14, 2008 @ 3:38 am
  17. Zinth said:

    im getting an error saying

    “Invalid src mime type: unknown”

    what does this mean????

    --April 28, 2008 @ 9:14 am
  18. FrenkyBoy said:

    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?

    --May 3, 2008 @ 2:42 pm
  19. Darren said:

    Can 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 pm
  20. Darren said:

    Guys, go ahead and grab the latest copy from the Google Code site. It should fix any mime type issues.

    --May 4, 2008 @ 12:50 pm
  21. os said:

    Mhm,
    image 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.

    --May 13, 2008 @ 8:49 am
  22. FrenkyBoy said:

    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



Trackbacks & Pingbacks

  1. Scripts, Releases and News » Curtis Henson:

    […] up is the release of TimThumb by Tim McDaniels. This was a script created for use in the Mimbo Pro Premium Wordpress and Darren […]

    --April 3, 2008 @ 4:18 pm
  2. TimThumb - PHP Image Resize Script - WebStockBox:

    […] : TimThumb - PHP Image Resize Script […]

    --April 4, 2008 @ 6:31 am
  3. Script Image resize, create thumbnail via url - TP Hilfe Forum:

    […] Image resize, create thumbnail via url TimThumb […]

    --April 4, 2008 @ 6:11 pm
  4. Resizing Images and Associating Them with Posts in Mimbo Pro » Darren Hoyt Dot Com:

    […] past, users had to manually crop and resize images with image-edit software. Mimbo Pro comes with an open-source script called TimThumb which resizes images on the fly. Throughout the theme, you’ll see code like […]

    --April 4, 2008 @ 7:50 pm
  5. Dynamic image resizing in PHP | Code.TechInterviews.com:

    […] Darren Hoyt we found a reference to TimThumb, a quick and fast PHP script for on-the-fly image resizing. Once […]

    --April 5, 2008 @ 12:52 am
  6. » TimThumb PHP Script Webcreatives:

    […] TimThumb PHP Script Related StuffSmart Image Resizer — Shifting PixelCSS Colors: Take Control Using PHPGalleria - a Javascript Image GalleryjQZoom - jquery pluginCreate Soft Edges for Images Using Css and JavaScriptAjaxorized » Image Transition Manager: image transitions with scriptaculous […]

    --April 5, 2008 @ 6:35 am
  7. WordPress TimThumb PHP Script:

    […] TimThumb is a small simple script that crops, zooms and resizes images for your WordPress blog or other application. The custom image resize script was created for the Mimbo Pro Theme and is now being used in a couple of other premium WordPress themes such as the Live Wire Series from Premium News Themes. Tim Thumb is now an open source project and available for download here. […]

    --April 5, 2008 @ 9:37 pm
  8. Trevor Davis | Blog | Weekly Link Round-Up #25:

    […] TimThumb PHP Script Released […]

    --April 5, 2008 @ 11:13 pm
  9. Skylog » Blog Archive » links for 2008-04-07:

    […] TimThumb PHP Script Released (tags: php) […]

    --April 7, 2008 @ 2:30 am
  10. links for 2008-04-07 « toonz:

    […] TimThumb PHP Script Released » Darren Hoyt Dot Com (tags: php resize images thumbnail) […]

    --April 7, 2008 @ 7:38 pm
  11. timthumb script php per thumbnails : sastgroup.com:

    […] web: http://www.darrenhoyt.com/2008/04/02/timthumb-php-script-released/ Share and Enjoy: These icons link to social bookmarking sites where readers can share and […]

    --April 9, 2008 @ 8:46 am
  12. Birgit’s & Uwe’s Blog » Blog Archive » Bilder einbinden mit TimThumb & iBox:

    […] Das ist ein kleiner Test für das Präsentieren von Bilden mit iBox und TimThumb. […]

    --April 12, 2008 @ 9:05 am
  13. Valontuoja » Blog Archive » Kaoottinen linkkidumppi:

    […] TimThumb PHP Script Released » Darren Hoyt Dot Com […]

    --April 19, 2008 @ 4:42 pm
  14. TimThumb - Fast And Easy Thumbnails Creation | Dezzain Studio:

    […] Darren Hoyt from darrenhoyt.com and Ben Gillbanks from binarymoon had work together to released this wonderful script that generated a very flexible and wicked thumbnails creation called TimThumb. […]

    --April 21, 2008 @ 10:51 pm
  15. Arthemia: Magazine-Blog Wordpress Theme Released - jubel and the unessentials:

    […] huh? Just upload any image using Wordpress image uploader, and the thumbnail is there. Thanks to Darren Hoyt for the awesome […]

    --May 2, 2008 @ 1:04 pm
  16. TimThumb | milo:

    […] on Apr 3 ⁄⁄ ⁄⁄ The custom image-resize script (TimThumb) created for Mimbo Pro is now available as an open-source p… Published in Design | Tags: CSS | Browse the Archives That’s all. Want more info? […]

    --May 6, 2008 @ 4:04 pm
  17. Links for Wed 7 May 2008 - Joseph Scott’s Blog:

    […] TimThumb PHP Script Released » Darren Hoyt Dot Com - Be able to adjust image size on the server, on the fly is very handy. Tags: image php resize thumbnail timthump […]

    --May 8, 2008 @ 12:52 pm
  18. TimThumb Pembuat Thumbnail · Eka Priatna:

    […] membuat sebuah thumbnail (apa sih bahasa Indonesianya?), Anda bisa memanfaatkan skrip TimThumb tanpa perlu lagi direpotkan oleh perangkat lunak pengolah citra seperti GIMP atau […]

    --May 9, 2008 @ 9:49 am


Leave a comment

(required)

(required)



  • rssRSS feed for comments on this post.