Changeset 57524 for trunk/src/wp-includes/media.php
- Timestamp:
- 02/02/2024 05:46:50 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r57294 r57524 4101 4101 require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php'; 4102 4102 require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php'; 4103 require_once ABSPATH . WPINC . '/class-avif-info.php'; 4103 4104 /** 4104 4105 * Filters the list of image editing library classes. … … 4203 4204 if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) { 4204 4205 $defaults['webp_upload_error'] = true; 4206 } 4207 4208 // Check if AVIF images can be edited. 4209 if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) { 4210 $defaults['avif_upload_error'] = true; 4205 4211 } 4206 4212 … … 5481 5487 * @since 5.7.0 5482 5488 * @since 5.8.0 Added support for WebP images. 5489 * @since 6.5.0 Added support for AVIF images. 5483 5490 * 5484 5491 * @param string $filename The file path. … … 5513 5520 } 5514 5521 5515 if ( false !== $info ) { 5522 if ( 5523 ! empty( $info ) && 5524 // Some PHP versions return 0x0 sizes from `getimagesize` for unrecognized image formats, including AVIFs. 5525 ! ( empty( $info[0] ) && empty( $info[1] ) ) 5526 ) { 5516 5527 return $info; 5517 5528 } … … 5542 5553 } 5543 5554 5555 // For PHP versions that don't support AVIF images, extract the image size info from the file headers. 5556 if ( 'image/avif' === wp_get_image_mime( $filename ) ) { 5557 $avif_info = wp_get_avif_info( $filename ); 5558 5559 $width = $avif_info['width']; 5560 $height = $avif_info['height']; 5561 5562 // Mimic the native return format. 5563 if ( $width && $height ) { 5564 return array( 5565 $width, 5566 $height, 5567 IMAGETYPE_AVIF, 5568 sprintf( 5569 'width="%d" height="%d"', 5570 $width, 5571 $height 5572 ), 5573 'mime' => 'image/avif', 5574 ); 5575 } 5576 } 5577 5544 5578 // The image could not be parsed. 5545 5579 return false; 5580 } 5581 5582 /** 5583 * Extracts meta information about an AVIF file: width, height, bit depth, and number of channels. 5584 * 5585 * @since 6.5.0 5586 * 5587 * @param string $filename Path to an AVIF file. 5588 * @return array { 5589 * An array of AVIF image information. 5590 * 5591 * @type int|false $width Image width on success, false on failure. 5592 * @type int|false $height Image height on success, false on failure. 5593 * @type int|false $bit_depth Image bit depth on success, false on failure. 5594 * @type int|false $num_channels Image number of channels on success, false on failure. 5595 * } 5596 */ 5597 function wp_get_avif_info( $filename ) { 5598 $results = array( 5599 'width' => false, 5600 'height' => false, 5601 'bit_depth' => false, 5602 'num_channels' => false, 5603 ); 5604 5605 if ( 'image/avif' !== wp_get_image_mime( $filename ) ) { 5606 return $results; 5607 } 5608 5609 // Parse the file using libavifinfo's PHP implementation. 5610 require_once ABSPATH . WPINC . '/class-avif-info.php'; 5611 5612 $handle = fopen( $filename, 'rb' ); 5613 if ( $handle ) { 5614 $parser = new Avifinfo\Parser( $handle ); 5615 $success = $parser->parse_ftyp() && $parser->parse_file(); 5616 fclose( $handle ); 5617 if ( $success ) { 5618 $results = $parser->features->primary_item_features; 5619 } 5620 } 5621 return $results; 5546 5622 } 5547 5623
Note: See TracChangeset
for help on using the changeset viewer.