image_resize in wp3.5 change to wp_get_image_editor and wont work

After 3.5 removed support image_resize and now says to use wp_get_image_editor as described here:

https://codex.wordpress.org/Function_Reference/wp_get_image_editor

Read More

Before (when it was image_resize), it would take in the image and the resize dimensions and it would resize the image and save the new file. Show as this code:

$thumb = image_resize($file, 80, 80, true);

After and trying to use the new function wp_get_image_editor doesnt quite work the same.

$image = wp_get_image_editor($file);

if ( ! is_wp_error( $image ) ) {
    $image->resize( 80, 80, true );
    $image->save( 'new_image.jpg' );
}

I want to be able to get the $thumb value after the resize() and save() actions are done.

Any ideas or insight? I dont think that the info page has enough detail about this.

Related posts

Leave a Reply

1 comment

  1. Figured it out after a lot of trial and error and a lot of var_dumps.

    $image = wp_get_image_editor($file);
    
    if ( ! is_wp_error( $image ) ) {
        $image->resize( $width, $height, true );
        $final_image = $image->save( $file );
    }
    

    Then i can use the $final_image array to get what i need.

    It actually saved me a step from what i was doing and seems to be a bit faster in regards to the processing vs image_resize()