Skip to content

Commit 620b66b

Browse files
Media: Update post mime type when image format is converted during upload.
When uploading HEIC files via the media library on servers that support HEIC, the image is correctly converted to JPEG on disk but the attachment post's `post_mime_type` remained `image/heic`. This updates `_wp_image_meta_replace_original()` to also update the post mime type when the saved image format differs from the original. Additionally fixes the REST API index to use `wp_get_image_editor_output_format()` so the `image_output_formats` response includes the default HEIC-to-JPEG mapping, enabling client-side media processing to be aware of it. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 5ec7922 commit 620b66b

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/wp-admin/includes/image.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ function _wp_image_meta_replace_original( $saved_data, $original_file, $image_me
209209
// Update the attached file meta.
210210
update_attached_file( $attachment_id, $new_file );
211211

212+
// Update the post mime type if the image was converted to a different format.
213+
if ( ! empty( $saved_data['mime-type'] ) ) {
214+
$post = get_post( $attachment_id );
215+
216+
if ( $post && $post->post_mime_type !== $saved_data['mime-type'] ) {
217+
wp_update_post(
218+
array(
219+
'ID' => $attachment_id,
220+
'post_mime_type' => $saved_data['mime-type'],
221+
)
222+
);
223+
}
224+
}
225+
212226
// Width and height of the new image.
213227
$image_meta['width'] = $saved_data['width'];
214228
$image_meta['height'] = $saved_data['height'];

src/wp-includes/rest-api/class-wp-rest-server.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,8 +1383,10 @@ public function get_index( $request ) {
13831383
$input_formats = array( 'image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif', 'image/heic' );
13841384
$output_formats = array();
13851385
foreach ( $input_formats as $mime_type ) {
1386-
/** This filter is documented in wp-includes/media.php */
1387-
$output_formats = apply_filters( 'image_editor_output_format', $output_formats, '', $mime_type );
1386+
$output_format = wp_get_image_editor_output_format( '', $mime_type );
1387+
if ( ! empty( $output_format[ $mime_type ] ) && $output_format[ $mime_type ] !== $mime_type ) {
1388+
$output_formats[ $mime_type ] = $output_format[ $mime_type ];
1389+
}
13881390
}
13891391
$available['image_output_formats'] = (object) $output_formats;
13901392

0 commit comments

Comments
 (0)