Changeset 50815 for trunk/src/wp-includes/media.php
- Timestamp:
- 05/05/2021 06:46:10 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r50814 r50815 4988 4988 */ 4989 4989 function wp_getimagesize( $filename, array &$image_info = null ) { 4990 if ( 4991 // Skip when running unit tests. 4992 ! defined( 'WP_RUN_CORE_TESTS' ) 4993 && 4994 // Return without silencing errors when in debug mode. 4995 defined( 'WP_DEBUG' ) && WP_DEBUG 4990 // Don't silence errors when in debug mode, unless running unit tests. 4991 if ( defined( 'WP_DEBUG' ) && WP_DEBUG 4992 && ! defined( 'WP_RUN_CORE_TESTS' ) 4996 4993 ) { 4997 4994 if ( 2 === func_num_args() ) { 4998 return _wp_get_image_size( $filename, $image_info );4995 $info = getimagesize( $filename, $image_info ); 4999 4996 } else { 5000 return _wp_get_image_size( $filename ); 5001 } 5002 } 5003 5004 /* 5005 * Silencing notice and warning is intentional. 5006 * 5007 * getimagesize() has a tendency to generate errors, such as 5008 * "corrupt JPEG data: 7191 extraneous bytes before marker", 5009 * even when it's able to provide image size information. 5010 * 5011 * See https://core.trac.wordpress.org/ticket/42480 5012 */ 5013 if ( 2 === func_num_args() ) { 5014 // phpcs:ignore WordPress.PHP.NoSilencedErrors 5015 return @_wp_get_image_size( $filename, $image_info ); 4997 $info = getimagesize( $filename ); 4998 } 5016 4999 } else { 5017 // phpcs:ignore WordPress.PHP.NoSilencedErrors 5018 return @_wp_get_image_size( $filename ); 5019 } 5000 /* 5001 * Silencing notice and warning is intentional. 5002 * 5003 * getimagesize() has a tendency to generate errors, such as 5004 * "corrupt JPEG data: 7191 extraneous bytes before marker", 5005 * even when it's able to provide image size information. 5006 * 5007 * See https://core.trac.wordpress.org/ticket/42480 5008 */ 5009 if ( 2 === func_num_args() ) { 5010 // phpcs:ignore WordPress.PHP.NoSilencedErrors 5011 $info = @getimagesize( $filename, $image_info ); 5012 } else { 5013 // phpcs:ignore WordPress.PHP.NoSilencedErrors 5014 $info = @getimagesize( $filename ); 5015 } 5016 } 5017 5018 if ( false !== $info ) { 5019 return $info; 5020 } 5021 5022 // For PHP versions that don't support WebP images, 5023 // extract the image size info from the file headers. 5024 if ( 'image/webp' === wp_get_image_mime( $filename ) ) { 5025 $webp_info = wp_get_webp_info( $filename ); 5026 $width = $webp_info['width']; 5027 $height = $webp_info['height']; 5028 5029 // Mimic the native return format. 5030 if ( $width && $height ) { 5031 return array( 5032 $width, 5033 $height, 5034 IMAGETYPE_WEBP, // phpcs:ignore PHPCompatibility.Constants.NewConstants.imagetype_webpFound 5035 sprintf( 5036 'width="%d" height="%d"', 5037 $width, 5038 $height 5039 ), 5040 'mime' => 'image/webp', 5041 ); 5042 } 5043 } 5044 5045 // The image could not be parsed. 5046 return false; 5020 5047 } 5021 5048 … … 5104 5131 return $type && 'lossy' === $type; 5105 5132 } 5106 5107 /**5108 * Gets the image size, with support for WebP images.5109 *5110 * @since 5.8.05111 * @access private5112 *5113 * @param string $filename The file path.5114 * @param array $imageinfo Extended image information, passed by reference.5115 * @return array|false Array of image information or false on failure.5116 */5117 function _wp_get_image_size( $filename, &$imageinfo = array() ) {5118 // Try getimagesize() first.5119 $info = getimagesize( $filename, $imageinfo );5120 5121 if ( false !== $info ) {5122 return $info;5123 }5124 5125 // For PHP versions that don't support WebP images,5126 // extract the image size info from the file headers.5127 if ( 'image/webp' === wp_get_image_mime( $filename ) ) {5128 $webp_info = wp_get_webp_info( $filename );5129 $width = $webp_info['width'];5130 $height = $webp_info['height'];5131 5132 // Mimic the native return format.5133 if ( $width && $height ) {5134 return array(5135 $width,5136 $height,5137 IMAGETYPE_WEBP, // phpcs:ignore PHPCompatibility.Constants.NewConstants.imagetype_webpFound5138 sprintf(5139 'width="%d" height="%d"',5140 $width,5141 $height5142 ),5143 'mime' => 'image/webp',5144 );5145 }5146 }5147 5148 // The image could not be parsed.5149 return false;5150 }
Note: See TracChangeset
for help on using the changeset viewer.