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.
Was it good/ useful/ a load of old rubbish? Let me know on Mastodon, or BlueSky (or Twitter X if you must).
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.