Using TimThumb Part 4: Moving the Crop Location

TimThumb is no longer supported or maintained.
More information →

Moving the crop position around is by far the most popular feature that has been requested for TimThumb. And today it has been officially released!

To be honest the cropping code was something I had put off as I wanted to keep things nice and easy to use; but then a month ago I found a comment on the TimThumb Google Code page that gave me a nice simple method for adding the alignment code.

TimThumb Cropping Alignment/ Positioning

The code allows you to align the cropping region to different edges of the image. This isn’t full positioning with x,y co-ordinates, but 99 times in 100 you won’t need that anyway. Since this reduces the complexity considerably it made implementation simpler.

Usage

Cropping alignment requires 1 extra parameter being added to the TimThumb query string. The letter a will let you set the alignment.

As with everything TimThumb the parameters are straight forward to understand. They are:

  • c : position in the center (this is the default)
  • t : align top
  • tr : align top right
  • tl : align top left
  • b : align bottom
  • br : align bottom right
  • bl : align bottom left
  • l : align left
  • r : align right

An example of this in use would be:

timthumb.php?src=image.jpg&w=100&h=100&a=t

Theme Integration

It would be no good adding this functionality if people using my themes couldn’t make use of it, so I have now added support for it to Elemental, TheLocal, Nominate, and Mimbo Pro. Usage varies slightly in each theme but the info needed has been added to the relevant theme documentation pages.

How was it for you? Let me know on BlueSky or Mastodon

(Please) Link to this page

Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.

Related Posts

05 Aug 2010

Using TimThumb part 1: Getting Started

TimThumb has always been built with simplicity in mind. However there are a few things it can do that have not been exposed before.Inspired by a comment from RBhavesh I have decided to write a series of posts in which...
19 Aug 2010

Using TimThumb Part 3: Image Filters

So far I have documented the basic TimThumb functionality, and how to resize images that are on external domains and now things can get interesting. In this part I will talk about some of the features that have been available...
06 Jul 2009

A Brief History of TimThumb

When we were building Mimbo Pro – Darren came up with the idea of automating the image thumbnail resizing – and this was the idea that sparked the development of TimThumb.This was all part of making the theme site as...
01 Apr 2015

The State of WordPress Themes #wcldn

I recently spoke on a panel at WordCamp London 2015e. Lance – who used to be the Theme Team lead at WordPress.com – asked me if I wanted to speak on a panel with him at WordCamp London 2015. I’ve...
14 Mar 2009

Mimbo Pro 2.0

A year ago – almost to the day – Darren and I released Mimbo Pro, a premium WordPress theme. Since then both WordPress, and our technical skills, have grown considerably and so we’re now ready to present to you, Mimbo...
26 Jun 2014

New TimThumb Exploit Found

It’s been reported today that there is a new TimThumb exploit found. Unfortunately nobody told me about this before the exploit was announced – in fact I found out about the bug through wptavern.com so I haven’t been able to...