Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/wp-admin/includes/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
6 changes: 4 additions & 2 deletions src/wp-includes/rest-api/class-wp-rest-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading