diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php index 95084b1db0576..e1bfb8e67558b 100644 --- a/src/wp-admin/includes/image.php +++ b/src/wp-admin/includes/image.php @@ -209,6 +209,20 @@ function _wp_image_meta_replace_original( $saved_data, $original_file, $image_me // Update the attached file meta. update_attached_file( $attachment_id, $new_file ); + // Update the post mime type if the image was converted to a different format. + if ( ! empty( $saved_data['mime-type'] ) ) { + $post = get_post( $attachment_id ); + + if ( $post && $post->post_mime_type !== $saved_data['mime-type'] ) { + wp_update_post( + array( + 'ID' => $attachment_id, + 'post_mime_type' => $saved_data['mime-type'], + ) + ); + } + } + // Width and height of the new image. $image_meta['width'] = $saved_data['width']; $image_meta['height'] = $saved_data['height']; diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php index 704a990298826..a95de2a8d5b8f 100644 --- a/src/wp-includes/rest-api/class-wp-rest-server.php +++ b/src/wp-includes/rest-api/class-wp-rest-server.php @@ -1383,8 +1383,10 @@ public function get_index( $request ) { $input_formats = array( 'image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif', 'image/heic' ); $output_formats = array(); foreach ( $input_formats as $mime_type ) { - /** This filter is documented in wp-includes/media.php */ - $output_formats = apply_filters( 'image_editor_output_format', $output_formats, '', $mime_type ); + $output_format = wp_get_image_editor_output_format( '', $mime_type ); + if ( ! empty( $output_format[ $mime_type ] ) && $output_format[ $mime_type ] !== $mime_type ) { + $output_formats[ $mime_type ] = $output_format[ $mime_type ]; + } } $available['image_output_formats'] = (object) $output_formats;