How Can I Resize WordPress Image Programmatically

I would like to resize the WordPress image programmatically via my custom WordPress plugin

You can use default WordPress function wp_get_image_editor

$image = wp_get_image_editor( 'image.jpg' );
if ( ! is_wp_error( $image ) ) {
    $image->rotate( 120 );
    $image->resize( 200, 200, true );
    $image->save( 'new_image.jpg' );
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Chibuike
6 years ago

Thanks for the code snippet it saved me many hours.

I needed to resize uploaded custom profile images for a membership website we are building and the images are uploaded into a custom folder. This code really helped, I adapted it to our use case: upload the image, resize & save a new copy, them delete the original image to save space.