• Hey all. I’ve been working hard on updating my plugin the ‘Easing Slider’. A fairly massive update is on the way, and being a slideshow plugin image resizing is always a hot topic.

    I had been using Timthumb (like a lot of people), but often spent quite a while looking for a WordPress based alternative. I came across the ‘vt_resize’ function, which initially I felt did the trick, until I found out it wouldn’t upscale images (which was vitally needed). It wasn’t a good enough solution.

    So I bit the bullet and decided to come up with my own function. It is heavily based on some of WordPress’s internal resizing functions, except it crops identically to Timthumb itself.

    It also supports the upcoming WordPress 3.5 update (an alternative function is used via an ‘if’ statement), which gives us access to some handy image manipulation classes to ease the pain.

    So far after a bit of testing it appears to be working very well. I’m really happy with it. It saves the resized images in the WordPress uploads folder, as per usual. This is great, because not only are the images resized but they are static files, which is ideal.

    I’ve created a Github page for the function here. It is released under GNU general public license, so feel free to use it as you wish!

    http://matthewruddy.github.com/Wordpress-Timthumb-alternative/index.html

    There is only one drawback: it won’t work with external images. It’s just too complicated and slow to do so, and probably not worth the effort. If you need to resize an external image, save it to your computer and upload it to the WordPress Media Library. Then use it from there.

    That’s it really. If anyone finds any bugs, then let me know and I’ll get them sorted quickly!

    Now you’ve no excuse to use Timthumb at all!

Viewing 15 replies - 1 through 15 (of 31 total)
  • I just wanted to say thanks very much for this – I’ve just come across it and have been trying it out on 3.5. Absolutely fantastic, well done. The functionality of TimThumb using built in WordPress functions – grand work fellah!

    Very nice. And extremely useful.

    One problem I am having is that I need to resize images to a specific size (400×250) and crop if the height is greater than 250. However, I need to control the cropping (Top, Middle, Bottom). Next time you’re fiddling with this, any change you can add support to control the cropping?

    Matthew, sorry about the fool question, but what’s the best way to include these functions in my theme?
    Just make a “include_once resize.php”, in my functions.php file?

    thanks!
    and congratulations for your great work!

    Thread Starter MatthewRuddy

    (@matthewruddy)

    Thanks for the great responses, glad to hear people are getting good use of it 🙂

    @dnavarrojr, controlling the crop positioning is something that has been suggested before but have yet to implement. Simply haven’t had the time I’m afraid. Definitely going to look into it when I can!

    @gustao, yes, that’s all it takes. Simply include the file or paste its contents into your themes functions.php file. Either will work nicely!

    @matthewruddy – Thanks for the great code! I have forked it and sent you a pull request. Just some small changes to reduce load on the DB.

    Matthew,

    any idea about this error (on a remote server)?

    Parse error: syntax error, unexpected ':' in /home/storage/bla/bla/bla/resize.php on line 45

    on my local mamp wordpress installations, everything works fine!
    Great work!!

    in time: PHP Version 5.2.17

    Thread Starter MatthewRuddy

    (@matthewruddy)

    Could be syntax errors with an older version of PHP. Try changing lines 45 & 46 to this:

    $width  = ( $width === NULL ) ?  get_option( 'thumbnail_size_w' ) : $width;
    $height = ( $height === NULL ) ? get_option( 'thumbnail_size_h' ) : $height;

    You’re right, Matthew!

    Again, thank you so much for your support and the great work!

    Thread Starter MatthewRuddy

    (@matthewruddy)

    Glad to hear 🙂 No problem at all!

    I have added Positional Cropping, here is the updated if($crop) snippet: https://gist.github.com/styledev/5042132

    Hi,

    I have just updated my site to WP 3.5.1 (late, yes) and now no thumbnails are appearing with the new posts on the main page. There are images associated with the individual posts on their page, but the scripts are not generating thumbnails (or even a div for the thumbnail to go in) on the index page.

    Is there an update to this theme that we need for 3.5.1?

    @onaicul – That is odd, I am running this code on multiple sites that are on WP 3.5.1.

    I would recommend turning on WP_Debug in wp-config.php and see if any errors are being thrown.

    Thread Starter MatthewRuddy

    (@matthewruddy)

    @onaicul – This isn’t a theme; it’s a standalone function for resizing images using native WordPress functionality. Not sure if your theme has included it, but are you sure this is related?

    The functionality would have nothing to do with native WordPress thumbnails.

    Hello, thanks for your answers.
    The problem is with timthumb i think.
    You can see the last 5 new posts dont have picture… http://www.perfeita.net

    Hey @onaicul – This thread is for an alternative to timthumb and not timthumb itself.

    You should go here: http://www.binarymoon.co.uk/projects/timthumb/

Viewing 15 replies - 1 through 15 (of 31 total)
  • The topic ‘Image Resizing Function – An Alternative to Timthumb’ is closed to new replies.