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:
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.
Whereas adding the attributes
[ttimg crop="t" height="150" width="500"]http://caramboo.com/wp-content/uploads/2011/09/blackbirds1.jpg[/ttimg]
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
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.
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
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.
Have a look on this page for some funky examples.