More information →
Recently, when I haven’t been working on WPAdvent, I have been tweaking and improving TimThumb. In fact there’s been a couple of cool new features added that make it a much more useful peice of kit.
The big changes boil down to speed, simplicity, and Youtube!
Speed
I’ve always been very conscious of the speed of TimThumb. I know that resizing images is slow and uses a lot of memory, so caching has been in there from the start. However I thought I would spend a few days trying to speed it up even more and the changes made have increased the speed a lot more that I had imagined. Some of the things I did to speed TimThumb up include:
- Move cache loading higher up in the code so that it does less processing if the cache file exists
- Improve browser caching
- Reduce the amount of regular expressions (processor intensive commands)
- Reduce the amount of file requests (file_exists, file age etc) – server intensive commands
- Do the cache cleaning after the image generation rather than before
All these add up to a script that is considerably faster, and uses considerably fewer server resources – so it should be a win for everyone.
Thanks go to indiepath, kieranjallen, and LeeWillis77 for their help with this.
Simplicity
When I was developing the offsite functionality I introduced a ‘temp’ directory requirement. At the time it was necessary as I wasn’t sure how the folder would be used, and was concerned there could be filename clashes. However Magnus from WooThemes mentioned that he’d tested it without and found there to be no problems – so it’s gone. The cache requirements now are a single folder. This should mean less debugging if there are problems. A simple change, but welcome none the less.
Youtube (beta!)
This one is a nice little easter egg. Lot’s of people have asked for Youtube video resizing and I thought it would be a cool thing to add. So now you can pass a Youtube video url to TimThumb as the image source and it will work out the video thumbnail and resize that.
This functionality has already been added to my Elemental WordPress theme framework so now if you embed a video in a post with no images then the post thumbnail will become the video thumbnail without any work from you.
An example of this is below – the link is for a festive Creature Comforts video.
timthumb.php?src=http://www.youtube.com/watch?v=9Ks8jtU5-fY&w=250&h=180
Which will give you:
I should point out that the Youtube functionality is in the beta stage. It’s in the active version of the script but I have only done light testing with it. If you have any problems then please do post a comment below and I will see if I can improve it some more.
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.