Image Resize: TimThumb PHP Script CodeUnit 17 DEC 2009

PHP-logoTimThumb, created and maintained by Tim McDaniels, Ben Gillbanks and Darren Hoyt, is a rather popular open source, image resizing PHP script, mostly used for generating thumbnails for blogging purposes on the fly. The script is fairly powerful, executes quickly and needs almost nothing from a developer in order to get it up and running on their own project.

The script makes use of the GD library to resize images based on the parameters used when calling the script. Thumbnails maintain aspect ratio and the script deals with jpg, gif and png files pretty well. It also has a caching system built in which helps keeps things fast.

In terms of parameters, the script allows you to set any of these for an image to be resized:

  • w: width
  • h: height
  • zc: zoom crop (0 or 1)
  • q: quality (default is 75 and max is 100)

And calling the script is as easy as this:

<img src=“/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1” alt=“”>

To read more about TimThumb and see it in action, visit Darren Hoyt’s site if you can, and to download the script itself, pay a visit to its Google Code home here.

Related Link:

About Craig Lotter

Software developer, husband and dad to two young ladies. Writer behind An Exploring South African. I don't have time for myself any more.