Changeset 58849
- Timestamp:
- 08/05/2024 04:11:40 AM (4 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/media/controllers/library.js
r57524 r58849 197 197 // If uploading, we know the filename but not the mime type. 198 198 if ( attachment.get('uploading') ) { 199 return /\.(jpe?g|png|gif|webp|avif )$/i.test( attachment.get('filename') );199 return /\.(jpe?g|png|gif|webp|avif|heic)$/i.test( attachment.get('filename') ); 200 200 } 201 201 -
trunk/src/wp-admin/includes/image.php
r57755 r58849 544 544 * @since 2.1.0 545 545 * @since 6.0.0 The `$filesize` value was added to the returned array. 546 * @since 6.7.0 The 'image/heic' mime type is supported. 546 547 * 547 548 * @param int $attachment_id Attachment ID to process. … … 556 557 $mime_type = get_post_mime_type( $attachment ); 557 558 558 if ( preg_match( '!^image/!', $mime_type ) && file_is_displayable_image( $file) ) {559 if ( 'image/heic' === $mime_type || ( preg_match( '!^image/!', $mime_type ) && file_is_displayable_image( $file ) ) ) { 559 560 // Make thumbnails and other intermediate sizes. 560 561 $metadata = wp_create_image_subsizes( $file, $attachment_id ); -
trunk/src/wp-includes/class-wp-image-editor-imagick.php
r58417 r58849 220 220 } 221 221 break; 222 case 'image/avif':223 222 default: 224 223 $this->image->setImageCompressionQuality( $quality ); … … 259 258 260 259 /* 261 * If we still don't have the image size, fall back to `wp_getimagesize`. This ensures AVIF images260 * If we still don't have the image size, fall back to `wp_getimagesize`. This ensures AVIF and HEIC images 262 261 * are properly sized without affecting previous `getImageGeometry` behavior. 263 262 */ 264 if ( ( ! $width || ! $height ) && 'image/avif' === $this->mime_type) {263 if ( ( ! $width || ! $height ) && ( 'image/avif' === $this->mime_type || 'image/heic' === $this->mime_type ) ) { 265 264 $size = wp_getimagesize( $this->file ); 266 265 $width = $size[0]; -
trunk/src/wp-includes/class-wp-image-editor.php
r57524 r58849 319 319 break; 320 320 case 'image/jpeg': 321 case 'image/avif':322 321 default: 323 322 $quality = $this->default_quality; … … 367 366 } 368 367 369 /** 370 * Filters the image editor output format mapping. 371 * 372 * Enables filtering the mime type used to save images. By default, 373 * the mapping array is empty, so the mime type matches the source image. 374 * 375 * @see WP_Image_Editor::get_output_format() 376 * 377 * @since 5.8.0 378 * 379 * @param string[] $output_format { 380 * An array of mime type mappings. Maps a source mime type to a new 381 * destination mime type. Default empty array. 382 * 383 * @type string ...$0 The new mime type. 384 * } 385 * @param string $filename Path to the image. 386 * @param string $mime_type The source image mime type. 387 */ 388 $output_format = apply_filters( 'image_editor_output_format', array(), $filename, $mime_type ); 368 $output_format = wp_get_image_editor_output_format( $filename, $mime_type ); 389 369 390 370 if ( isset( $output_format[ $mime_type ] ) -
trunk/src/wp-includes/compat.php
r58763 r58849 550 550 define( 'IMG_AVIF', IMAGETYPE_AVIF ); 551 551 } 552 553 // IMAGETYPE_HEIC constant is not yet defined in PHP as of PHP 8.3. 554 if ( ! defined( 'IMAGETYPE_HEIC' ) ) { 555 define( 'IMAGETYPE_HEIC', 99 ); 556 } -
trunk/src/wp-includes/functions.php
r58848 r58849 2707 2707 */ 2708 2708 if ( $is_image ) { 2709 /** This filter is documented in wp-includes/class-wp-image-editor.php */ 2710 $output_formats = apply_filters( 'image_editor_output_format', array(), $_dir . $filename, $mime_type ); 2709 $output_formats = wp_get_image_editor_output_format( $_dir . $filename, $mime_type ); 2711 2710 $alt_types = array(); 2712 2711 … … 3121 3120 'image/webp' => 'webp', 3122 3121 'image/avif' => 'avif', 3122 'image/heic' => 'heic', 3123 3123 ) 3124 3124 ); … … 3300 3300 * @since 5.8.0 Added support for WebP images. 3301 3301 * @since 6.5.0 Added support for AVIF images. 3302 * @since 6.7.0 Added support for HEIC images. 3302 3303 * 3303 3304 * @param string $file Full path to the file. … … 3372 3373 ) { 3373 3374 $mime = 'image/avif'; 3375 } 3376 3377 if ( 3378 isset( $magic[1] ) && 3379 isset( $magic[2] ) && 3380 'ftyp' === hex2bin( $magic[1] ) && 3381 ( 'heic' === hex2bin( $magic[2] ) || 'heif' === hex2bin( $magic[2] ) ) 3382 ) { 3383 $mime = 'image/heic'; 3374 3384 } 3375 3385 } catch ( Exception $e ) { -
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 } -
trunk/src/wp-includes/post.php
r58437 r58849 6830 6830 switch ( $type ) { 6831 6831 case 'image': 6832 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp', 'avif' );6832 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp', 'avif', 'heic' ); 6833 6833 return in_array( $ext, $image_exts, true ); 6834 6834 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r58706 r58849 532 532 } 533 533 534 $supported_types = array( 'image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif' );534 $supported_types = array( 'image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif', 'image/heic' ); 535 535 $mime_type = get_post_mime_type( $attachment_id ); 536 536 if ( ! in_array( $mime_type, $supported_types, true ) ) { -
trunk/tests/phpunit/tests/functions.php
r58570 r58849 1356 1356 'image/avif', 1357 1357 ), 1358 // HEIC. 1359 array( 1360 DIR_TESTDATA . '/images/test-image.heic', 1361 'image/heic', 1362 ), 1358 1363 ); 1359 1364 … … 1385 1390 1386 1391 /** 1387 * Data pro fider for test_wp_getimagesize().1392 * Data provider for test_wp_getimagesize(). 1388 1393 */ 1389 1394 public function data_wp_getimagesize() { … … 1541 1546 return $data; 1542 1547 } 1548 1549 /** 1550 * Tests that wp_getimagesize() correctly handles HEIC image files. 1551 * 1552 * @ticket 53645 1553 */ 1554 public function test_wp_getimagesize_heic() { 1555 if ( ! is_callable( 'exif_imagetype' ) && ! function_exists( 'getimagesize' ) ) { 1556 $this->markTestSkipped( 'The exif PHP extension is not loaded.' ); 1557 } 1558 1559 $file = DIR_TESTDATA . '/images/test-image.heic'; 1560 1561 $editor = wp_get_image_editor( $file ); 1562 if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/heic' ) ) { 1563 $this->markTestSkipped( 'No HEIC support in the editor engine on this system.' ); 1564 } 1565 1566 $expected = array( 1567 50, 1568 50, 1569 IMAGETYPE_HEIC, 1570 'width="50" height="50"', 1571 'mime' => 'image/heic', 1572 ); 1573 $result = wp_getimagesize( $file ); 1574 $this->assertSame( $expected, $result ); 1575 } 1576 1543 1577 1544 1578 /** -
trunk/tests/phpunit/tests/image/functions.php
r57931 r58849 238 238 'test-image.psd', 239 239 'test-image-zip.tiff', 240 'test-image.heic', 240 241 ); 241 242 -
trunk/tests/phpunit/tests/image/resize.php
r57524 r58849 115 115 } 116 116 117 /** 118 * Test resizing HEIC image. 119 * 120 * @ticket 53645 121 */ 122 public function test_resize_heic() { 123 $file = DIR_TESTDATA . '/images/test-image.heic'; 124 $editor = wp_get_image_editor( $file ); 125 126 // Check if the editor supports the HEIC mime type. 127 if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/heic' ) ) { 128 $this->markTestSkipped( 'No HEIC support in the editor engine on this system.' ); 129 } 130 131 $image = $this->resize_helper( $file, 25, 25 ); 132 133 list( $w, $h, $type ) = wp_getimagesize( $image ); 134 135 unlink( $image ); 136 137 $this->assertSame( 'test-image-25x25.jpg', wp_basename( $image ) ); 138 $this->assertSame( 25, $w ); 139 $this->assertSame( 25, $h ); 140 $this->assertSame( IMAGETYPE_JPEG, $type ); 141 } 142 117 143 public function test_resize_larger() { 118 144 // image_resize() should refuse to make an image larger. … … 236 262 } 237 263 238 return $ dest_file;264 return $saved['path']; 239 265 } 240 266 }
Note: See TracChangeset
for help on using the changeset viewer.