Custom Thumbnail Sizes Using The Attached Image & Timthumb
I promised a while ago I would do this tutorial and I’m ashamed to say I never got round to it. I wouldn’t care it isn’t that complicated so it would have only taken me about 20-30 minutes to write. Oh well, better late than never.
To use The Attached Image along with Timthumbs is easy. I am assuming you have placed the Timthumb script in a folder called timthumb
in your current active theme folder. You can download timthumb from it’s Google Code site.
Here we go. Here is an example of creating a 100×100 square thumbnail.
1 |
<img src="<?php bloginfo('stylesheet_directory'); ?>/timthumb/timthumb.php?src=<?php the_attached_image('img_tag=false'); ?>&w=100&h=100&zc=1" /> |
That will create a 100×100 image using timthumb. As long as your WP small thumbnail size is greater than 100×100 that will work fine. If not supply the img_size
parameter with medium, large, or full to use a larger image. It’s important you do that as it will save you server resources to use timthumb on an image only moderately larger than the size you want. For example, don’t ask for the full image if you only want to make a 50×50 thumbnail, use the thumb size instead.
Why use timthumb? Well you can only have 1 thumbnail generated within WP that is cropped square, so if you need multiple sizes of cropped thumbnails then it’s great. Generally though it’s used for featured posts sections in theme layouts.
Anyway I hope that helps anyone wanting to generate thumbnails using TAI & Timthumb. If you’ve any questions leave them in the comments or send them to me via the contact page.