I spent a while recently, playing around with the Tim Thumb image cropping and resizing script. I wanted a way of using Tim Thumb in WordPress where I could enter a simple shortcode into the WordPress editor and have Tim Thumb work its magic on an image. After writing a function to place into a WordPress theme’s functions.php I was persuaded by @chrismou to turn it into a simple plugin.
If you just want to cut to the chase, it’s here:
Version 0.2
So what does it do?
TT Shortcodes makes the ttimg shortcode available to you. It consists of a simple pair of opening and closing blocks wrapped around an image URL.
For example:
[ttimg]http://caramboo.com/wp-content/uploads/2011/09/blackbirds1.jpg[/ttimg]
Produces this:
Whereas adding the attributes crop="t", height="150" and width="500"
[ttimg crop="t" height="150" width="500"]http://caramboo.com/wp-content/uploads/2011/09/blackbirds1.jpg[/ttimg]
Produces this:
I’ve also added (as of v0.2) the webshot attribute. You need to install stuff on your server to get this to work so it’s disabled by default. Full details on how to get it working are found in the timthumb.php file.
Pretty neat huh!
The attributes for the ttimg shortcode are the same as the ones used for Tom Thumb except I gave them real names, if you see what I mean.
So:
| Tim Thumb | Shortcode |
|---|---|
| w | width |
| h | height |
| f | filter |
| a | crop |
| zc | zoom |
| q | quality |
| s | sharpen |
| webshot | webshot |
Tim Thumb
I’ve bundled the latest (secure) version of Tim Thumb with the plugin. I’ve also created a timbthumb-config.php file for customised Tim Thumb use. It’s fully documented in the file.
To install the plugin, all you have to do is unarchive the zip or tar.gz file in your wp-content/plugins directory then make sure your new tt_shortcodes directory has two sub-directories named cache and temp. If they’re missing for whatever reason, simply create them:
mkdir temp cache
You must also make them world writeable:
chmod 777 temp/ cache/
And that’s it, you should be good to go!
If you get something wrong, such as not making the two sub-directories (cache and temp) writeable, providing a broken link, or linking to a non-image file, you’ll see this little guy:
((Photo is used under a Creative Commons Attribution-NonCommercial-ShareAlike 2.0 Generic (CC BY-NC-SA 2.0) licence and was created by Dave King))
It’s then time to check your installation or post/page.
Examples
Have a look on this page for some funky examples.
Nice
Hi Dave,
This is exactly what I have been looking for but I just can not get it work… Any ideas on what I am doing wrong? Any help would be appreciated. Thanks in advance.
sorry, i just figured it out
Great plugin, cheers.
Is there a way of making the resulting image clickable so that image appears full size in a lightboxfor example?