Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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.

share|improve this question
add comment

1 Answer

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()

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.