I'm using wp_get_image_editor()
to resize and save an image that is being uploaded to the Media Library.
$image = wp_get_image_editor( $newattachment_url );
if ( ! is_wp_error( $image ) ) {
$image->rotate( 0 );
$image->resize( 300, 300, false );
$image->save('resizedimage.jpg');
}
This is working fine however it is saving to the root of WordPress. How can I instead upload this file to the media library? I want to have the orignal image and the resized image in the media library.
$newattachment_url
is the URL of the orignally uploaded image.