diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php index 370025d927d2f..cbc62b49ea17b 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php @@ -626,7 +626,7 @@ public function edit_media_item( $request ) { $width = (int) round( ( $size['width'] * $args['width'] ) / 100.0 ); $height = (int) round( ( $size['height'] * $args['height'] ) / 100.0 ); - if ( $size['width'] !== $width && $size['height'] !== $height ) { + if ( $size['width'] !== $width || $size['height'] !== $height ) { $result = $image_editor->crop( $crop_x, $crop_y, $width, $height ); if ( is_wp_error( $result ) ) { diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index 074c710c740f5..737c32b8e1ab1 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -2381,6 +2381,43 @@ public function test_edit_image_crop() { ); } + /** + * @ticket 61514 + * @requires function imagejpeg + */ + public function test_edit_image_crop_one_axis() { + wp_set_current_user( self::$superadmin_id ); + $attachment = self::factory()->attachment->create_upload_object( self::$test_file ); + + $this->setup_mock_editor(); + WP_Image_Editor_Mock::$size_return = array( + 'width' => 640, + 'height' => 480, + ); + + WP_Image_Editor_Mock::$edit_return['crop'] = new WP_Error(); + + $request = new WP_REST_Request( 'POST', "/wp/v2/media/{$attachment}/edit" ); + $request->set_body_params( + array( + 'x' => 50, + 'y' => 0, + 'width' => 10, + 'height' => 100, + 'src' => wp_get_attachment_image_url( $attachment, 'full' ), + + ) + ); + $response = rest_do_request( $request ); + $this->assertErrorResponse( 'rest_image_crop_failed', $response, 500 ); + + $this->assertCount( 1, WP_Image_Editor_Mock::$spy['crop'] ); + $this->assertSame( + array( 320, 0, 64, 480 ), + WP_Image_Editor_Mock::$spy['crop'][0] + ); + } + /** * @ticket 44405 * @requires function imagejpeg