vt_resize.php – image_resize deprecated

Wordpress 3.5 is here and those who are using the great Victor Teixeira image resize script some warnings might have appeared on your WordPress installation. The image_resize function is still working, but deprecated (in favor of the “wp_get_image_editor” function). This means that it should stop working someday.

I took a look into the code and found a way to replace the old function. The first thing to do is search for the “image_resize” string and comment that line of code (just like shown on the first line of the code below). Then insert the following lines of code:

//$new_img_path = image_resize( $file_path, $width, $height, $crop, NULL, NULL, 100 );
$editor = wp_get_image_editor( $file_path );
if ( is_wp_error( $editor ) )
return $editor;
$editor->set_quality( 100 );
$resized = $editor->resize( $width, $height, $crop );
$dest_file = $editor->generate_filename( NULL, NULL );
$saved = $editor->save( $dest_file );
if ( is_wp_error( $saved ) )
return $saved;
$new_img_path=$dest_file;

This will keep this script working perfectly for the next 30 years! Well, maybe not that long…

Edit: in the meantime I have made some changes and adjustments to the script. One of the things that I did was adding the retina images option. If true this option will serve images and scale them to 50% of their size so that they look good on retina devices.

You can find the latest version of the script here: https://gist.github.com/Pirenko/6734d0689b3629cd370f

Web Designer
Web enthusiast since ever and full-time Web Designer since January 2012.
Delivering Premium WordPress Themes and freelance work to clients worldwide.

5 Comments

on vt_resize.php – image_resize deprecated.
  1. Victor Teixeira
    -

    Hi, just saw your post… Glad you updated my old function… Thanks

  2. Jacob Ross
    -

    Super cool.. I was just reading through this function and here is the guy who wrote it. Thanks, Victor

  3. -

    Thanks for updating the function. This is what I was looking for.

  4. -

    It is now the year 2014 bordering on 2015, and I\’ve found that vt_resize works perfectly for me, are there any known issues with using it at this time?

    • Pirenko
      -

      Hi,
      I\’m still using it on all of my themes. I\’ve made some edits in the meantime and I have added just a link to a Gist if you are interested. You will find this link on the bottom of the article just above.
      Thanks!

Please wait...

Struggling to Monetize Your Instagram account?

Please check our new product: Spotsy! It is a free web service that allows any Instagram user to create a website in less than 5 minutes.
Learn More →