• MatthewRuddy

    (@matthewruddy)


    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!

    https://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 - 16 through 30 (of 31 total)
  • Hey!

    I would really like to use your script but unfortanetely it only gives me back 150x150px in size no matter what values i put in. It only seems to grab the get_option( ‘thumbnail_size_w’ ) values.

    Have tried it in the twentyeleven theme and the same thing happens there.

    Any idea why?

    Thread Starter MatthewRuddy

    (@matthewruddy)

    Are you sure the dimensions are being entered correctly and as integers? Should work fine – no one has reported any issues like this.

    Unfortunately, yes.

    The following:
    <?php
    $image_resized = matthewruddy_image_resize( ‘https://localhost/bohus/wp-content/uploads/2013/06/bohus-1.jpg&#8217;, 300, 200, true, false );

    echo $image_resized[‘width’];
    echo $image_resized[‘url’];
    ?>

    Gives me:
    150https://localhost/bohus/wp-content/uploads/2013/06/bohus-1-150×150.jpg

    I have disabled all the plugins and are using the twentyeleven theme.

    Just did a clean install from the latest WordPress version and the problem remains. I’m running localhost Uniserver on my computer. Can it be problems with the server settings?

    Thread Starter MatthewRuddy

    (@matthewruddy)

    Could be that your version of PHP doesn’t include either the GD_Library or Imagemagick extensions. WordPress requires one of either for the resizing functionality to work.

    Can you confirm that you have these PHP packages installed?

    I get this from phpinfo():

    GD Support enabled
    GD Version bundled (2.0.34 compatible)
    FreeType Support enabled
    FreeType Linkage with freetype
    FreeType Version 2.4.10
    GIF Read Support enabled
    GIF Create Support enabled
    JPEG Support enabled
    libJPEG Version 8
    PNG Support enabled
    libPNG Version 1.2.50
    WBMP Support enabled
    XPM Support enabled
    libXpm Version 30411
    XBM Support enabled

    Thread Starter MatthewRuddy

    (@matthewruddy)

    Not sure what to suggest then. Hard to tell what could be going on from here.

    Try it from your webhost, and ensure the images you’re using are larger than the specified dimensions – the script won’t resize images smaller than the dimensions specified.

    Other than that, fairly clueless. Very sorry! Wish I could be of better assistance.

    No problem Matthew! Thank you anyway! I will try it out on Mamp on mac and on my dev-server.

    I have some more questions that also might be of interest for future readers:
    Will this script increase loading time compared to using add_image_size?
    Are there any other disadvantages compared to add_image_size?

    And my main problem with add_image_size:
    Will the images reload after you edit them with WP’s Media Editor (after manually cropping for example)?

    Thank you in advance and good work with the script. Can’t believe that this isnt built in WP function.

    Thread Starter MatthewRuddy

    (@matthewruddy)

    Regarding your questions:

    add_image_size won’t resize any images added before the new image size is added, so you’d need to use a plugin such as Regenerate Thumbnails to refresh all of your image sizes. You’d also have to do this every time you change your image dimensions as well, which can become a pain when testing. Alternatively, this resizing script resizes the images on-the-fly, just like Timthumb. No need to refresh anything.

    On the very first page load, when the resized image has to be generated, yes there will be a slower load time, but after that it is as quick as if the function wasn’t being used. Once the resized image is created, it’s saved in the WordPress uploads directory as usual and loaded from there – no PHP resizing required after that first initial page load.

    If you alter the image sizes, the script will simply generate a new resized image. All resized images are deleted when the image itself is deleted from the Media Library, so nothing gets left behind.

    Hope that helps in answering your questions. Feel free to ask anymore if you have them ?? Hope I’ve been clear!

    Thank you Matthew! You have been absolutely clear.

    I can’t get this to work though.
    I have tried this both on my local mamp server (mac) and on my webhost.
    The problem remains. I get 150×150 size no matter what i do. Too bad. Really looked forward to working with this script!

    Thread Starter MatthewRuddy

    (@matthewruddy)

    Very sorry Anton, not sure what could be going wrong! Hope you can find an alternative solution ??

    I weirdly have the same issue. Whatever sizes I give the script, it always exports them 150×150
    see this here:
    https://d.screenagers.at/quivogne/archive/products/diskator-m-2/
    my code:

    <?php
    $imgwidth=364;
    $imgheight=240;
    $imgresized= matthewruddy_image_resize( $src, $imgwidth, $imgheight);
    ?>
    <img alt=”<?php echo esc_attr($alt); ?>” src=”<?php echo $imgresized[‘url’]; ?>” />

    Thread Starter MatthewRuddy

    (@matthewruddy)

    Very unusual! Haven’t managed to figure this one out yet, very sorry!

    I think the issue with the 150×150 has to do with lines 45 and 46 again. By the looks of it the conditionals are set backward forcing the width and height to set as the default 150×150

    Thread Starter MatthewRuddy

    (@matthewruddy)

    Yes, you’re right. Well spotted! Came from a recent pull request, must have missed it.

    Thanks a million! Been fixed now – just pushed the changes.

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