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.

Let me know what you think on Mastodon, or BlueSky (or Twitter X if you must).

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...
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...
12 Aug 2011

TimThumb 2.0

Ok – so – TimThumb. I am sure many people have seen this already but some code exploits were recently discovered in TimThumb. Now that everything is under control once more I thought I would explain what happened and what...
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...
22 Nov 2014

WordPress 4.1 Improvements for Theme Developers

WordPress 4.1 is bringing with it a couple of cool new additions for theme developers. They’re things that are currently a bit messy to implement in themes. For me they are things that I do the same way in all...
23 Jan 2011

How to Contribute to TimThumb

The Google Code blog has recently announced a new method for modifying code committed to the site. They have created an online code editor that can be used by anyone.This is fantastic for people who want to contribute to any...