@@ -4064,8 +4064,7 @@ function wp_get_image_editor( $path, $args = array() ) {
4064
4064
4065
4065
// Check and set the output mime type mapped to the input type.
4066
4066
if ( isset ( $ args ['mime_type ' ] ) ) {
4067
- /** This filter is documented in wp-includes/class-wp-image-editor.php */
4068
- $ output_format = apply_filters ( 'image_editor_output_format ' , array (), $ path , $ args ['mime_type ' ] );
4067
+ $ output_format = wp_get_image_editor_output_format ( $ path , $ args ['mime_type ' ] );
4069
4068
if ( isset ( $ output_format [ $ args ['mime_type ' ] ] ) ) {
4070
4069
$ args ['output_mime_type ' ] = $ output_format [ $ args ['mime_type ' ] ];
4071
4070
}
@@ -4224,6 +4223,11 @@ function wp_plupload_default_settings() {
4224
4223
$ defaults ['avif_upload_error ' ] = true ;
4225
4224
}
4226
4225
4226
+ // Check if HEIC images can be edited.
4227
+ if ( ! wp_image_editor_supports ( array ( 'mime_type ' => 'image/heic ' ) ) ) {
4228
+ $ defaults ['heic_upload_error ' ] = true ;
4229
+ }
4230
+
4227
4231
/**
4228
4232
* Filters the Plupload default settings.
4229
4233
*
@@ -5483,12 +5487,17 @@ function _wp_add_additional_image_sizes() {
5483
5487
* Callback to enable showing of the user error when uploading .heic images.
5484
5488
*
5485
5489
* @since 5.5.0
5490
+ * @since 6.7.0 The default behavior is to enable heic uplooads as long as the server
5491
+ * supports the format. The uploads are converted to JPEG's by default.
5486
5492
*
5487
5493
* @param array[] $plupload_settings The settings for Plupload.js.
5488
5494
* @return array[] Modified settings for Plupload.js.
5489
5495
*/
5490
5496
function wp_show_heic_upload_error ( $ plupload_settings ) {
5491
- $ plupload_settings ['heic_upload_error ' ] = true ;
5497
+ // Check if HEIC images can be edited.
5498
+ if ( ! wp_image_editor_supports ( array ( 'mime_type ' => 'image/heic ' ) ) ) {
5499
+ $ plupload_init ['heic_upload_error ' ] = true ;
5500
+ }
5492
5501
return $ plupload_settings ;
5493
5502
}
5494
5503
@@ -5586,6 +5595,29 @@ function wp_getimagesize( $filename, ?array &$image_info = null ) {
5586
5595
}
5587
5596
}
5588
5597
5598
+ // For PHP versions that don't support HEIC images, extract the size info using Imagick when available.
5599
+ if ( 'image/heic ' === wp_get_image_mime ( $ filename ) ) {
5600
+ $ editor = wp_get_image_editor ( $ filename );
5601
+ if ( is_wp_error ( $ editor ) ) {
5602
+ return false ;
5603
+ }
5604
+ // If the editor for HEICs is Imagick, use it to get the image size.
5605
+ if ( $ editor instanceof WP_Image_Editor_Imagick ) {
5606
+ $ size = $ editor ->get_size ();
5607
+ return array (
5608
+ $ size ['width ' ],
5609
+ $ size ['height ' ],
5610
+ IMAGETYPE_HEIC ,
5611
+ sprintf (
5612
+ 'width="%d" height="%d" ' ,
5613
+ $ size ['width ' ],
5614
+ $ size ['height ' ]
5615
+ ),
5616
+ 'mime ' => 'image/heic ' ,
5617
+ );
5618
+ }
5619
+ }
5620
+
5589
5621
// The image could not be parsed.
5590
5622
return false ;
5591
5623
}
@@ -6069,3 +6101,37 @@ function wp_high_priority_element_flag( $value = null ) {
6069
6101
6070
6102
return $ high_priority_element ;
6071
6103
}
6104
+
6105
+ /**
6106
+ * Determines the output format for the image editor.
6107
+ *
6108
+ * @since 6.7.0
6109
+ * @access private
6110
+ *
6111
+ * @param string $filename Path to the image.
6112
+ * @param string $mime_type The source image mime type.
6113
+ * @return string[] An array of mime type mappings.
6114
+ */
6115
+ function wp_get_image_editor_output_format ( $ filename , $ mime_type ) {
6116
+ /**
6117
+ * Filters the image editor output format mapping.
6118
+ *
6119
+ * Enables filtering the mime type used to save images. By default,
6120
+ * the mapping array is empty, so the mime type matches the source image.
6121
+ *
6122
+ * @see WP_Image_Editor::get_output_format()
6123
+ *
6124
+ * @since 5.8.0
6125
+ * @since 6.7.0 The default was changed from array() to array( 'image/heic' => 'image/jpeg' ).
6126
+ *
6127
+ * @param string[] $output_format {
6128
+ * An array of mime type mappings. Maps a source mime type to a new
6129
+ * destination mime type. Default maps uploaded HEIC images to JPEG output.
6130
+ *
6131
+ * @type string ...$0 The new mime type.
6132
+ * }
6133
+ * @param string $filename Path to the image.
6134
+ * @param string $mime_type The source image mime type.
6135
+ */
6136
+ return apply_filters ( 'image_editor_output_format ' , array ( 'image/heic ' => 'image/jpeg ' ), $ filename , $ mime_type );
6137
+ }
0 commit comments