Changeset 58849 for trunk/src/wp-includes/media.php
- Timestamp:
- 08/05/2024 04:11:40 AM (15 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/media.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r58773 r58849 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'] ]; … … 4223 4222 if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) { 4224 4223 $defaults['avif_upload_error'] = true; 4224 } 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; 4225 4229 } 4226 4230 … … 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. … … 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 } … … 5583 5592 ), 5584 5593 'mime' => 'image/avif', 5594 ); 5595 } 5596 } 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', 5585 5617 ); 5586 5618 } … … 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 }
Note: See TracChangeset
for help on using the changeset viewer.