Changeset 50814
- Timestamp:
- 05/05/2021 05:06:17 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/compat.php
r50810 r50814 372 372 } 373 373 374 // WebP constants may not be defined, even in cases where the format is supported.374 // WebP constants are only defined in PHP 7.1+. 375 375 if ( ! defined( 'IMAGETYPE_WEBP' ) ) { 376 376 define( 'IMAGETYPE_WEBP', 18 ); -
trunk/src/wp-includes/functions.php
r50810 r50814 3080 3080 } 3081 3081 3082 // Add WebP fallback detection when image library doesn't support WebP. 3083 // Note: detection values come from LibWebP, see 3084 // https://github.com/webmproject/libwebp/blob/master/imageio/image_dec.c#L30 3082 /* 3083 * Add WebP fallback detection when image library doesn't support WebP. 3084 * Note: detection values come from LibWebP, see 3085 * https://github.com/webmproject/libwebp/blob/master/imageio/image_dec.c#L30 3086 */ 3085 3087 $magic = bin2hex( $magic ); 3086 3088 if ( -
trunk/src/wp-includes/media.php
r50810 r50814 5025 5025 * @since 5.8.0 5026 5026 * 5027 * @param [type]$filename Path to a WebP file.5027 * @param string $filename Path to a WebP file. 5028 5028 * @return array $webp_info { 5029 5029 * An array of WebP image information. … … 5039 5039 $height = false; 5040 5040 $type = false; 5041 5041 5042 if ( ! 'image/webp' === wp_get_image_mime( $filename ) ) { 5042 5043 return compact( 'width', 'height', 'type' ); 5043 5044 } 5045 5044 5046 try { 5045 5047 $handle = fopen( $filename, 'rb' ); … … 5084 5086 } catch ( Exception $e ) { 5085 5087 } 5088 5086 5089 return compact( 'width', 'height', 'type' ); 5087 5090 } … … 5098 5101 $webp_info = wp_get_webp_info( $filename ); 5099 5102 $type = $webp_info['type']; 5103 5100 5104 return $type && 'lossy' === $type; 5101 5105 } … … 5114 5118 // Try getimagesize() first. 5115 5119 $info = getimagesize( $filename, $imageinfo ); 5120 5116 5121 if ( false !== $info ) { 5117 5122 return $info; 5118 5123 } 5119 // For PHP versions that don't support WebP images, extract the image 5120 // size info from the file headers. 5124 5125 // For PHP versions that don't support WebP images, 5126 // extract the image size info from the file headers. 5121 5127 if ( 'image/webp' === wp_get_image_mime( $filename ) ) { 5122 5128 $webp_info = wp_get_webp_info( $filename ); … … 5124 5130 $height = $webp_info['height']; 5125 5131 5126 5132 // Mimic the native return format. 5127 5133 if ( $width && $height ) { 5128 5134 return array( -
trunk/tests/phpunit/tests/functions.php
r50810 r50814 1241 1241 if ( is_array( $expected ) ) { 1242 1242 foreach ( $expected as $k => $v ) { 1243 $this->assert Equals( true, isset( $result[ $k ] ));1244 $this->assert Equals( $expected[ $k ], $result[ $k ] );1243 $this->assertArrayHasKey( $k, $result ); 1244 $this->assertSame( $expected[ $k ], $result[ $k ] ); 1245 1245 } 1246 1246 } else { 1247 $this->assert Equals( $expected, $result );1247 $this->assertSame( $expected, $result ); 1248 1248 } 1249 1249 } … … 1313 1313 1314 1314 /** 1315 * Data provider for test_wp_get_image_mime() ;1315 * Data provider for test_wp_get_image_mime(). 1316 1316 */ 1317 1317 public function _wp_get_image_mime() { … … 1368 1368 1369 1369 /** 1370 * Data profider for test_wp_getimagesize() ;1370 * Data profider for test_wp_getimagesize(). 1371 1371 */ 1372 1372 public function data_wp_getimagesize() { -
trunk/tests/phpunit/tests/image/editor.php
r50810 r50814 206 206 public function test_wp_get_webp_info( $file, $expected ) { 207 207 $editor = wp_get_image_editor( $file ); 208 208 209 if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/webp' ) ) { 209 $this->markTestSkipped( sprintf( 'Skipping test: no WebP support in the editor engine %s on this system.', $this->editor_engine ) ); 210 } else { 211 $file_data = wp_get_webp_info( $file ); 212 $this->assertSame( $file_data, $expected ); 210 $this->markTestSkipped( sprintf( 'No WebP support in the editor engine %s on this system.', $this->editor_engine ) ); 213 211 } 214 } 215 216 /** 217 * Data provider for test_wp_get_webp_info(); 212 213 $file_data = wp_get_webp_info( $file ); 214 $this->assertSame( $file_data, $expected ); 215 } 216 217 /** 218 * Data provider for test_wp_get_webp_info(). 218 219 */ 219 220 public function _test_wp_get_webp_info() { -
trunk/tests/phpunit/tests/image/functions.php
r50810 r50814 100 100 $file = DIR_TESTDATA . '/images/test-image.webp'; 101 101 $editor = wp_get_image_editor( $file ); 102 if ( ( ! is_wp_error( $editor ) ) && $editor->supports_mime_type( 'image/webp' ) ) { 102 103 if ( ! is_wp_error( $editor ) && $editor->supports_mime_type( 'image/webp' ) ) { 103 104 $files = array_merge( 104 105 $files, -
trunk/tests/phpunit/tests/image/resize.php
r50810 r50814 71 71 // Check if the editor supports the webp mime type. 72 72 if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/webp' ) ) { 73 $this->markTestSkipped( sprintf( ' Skipping test: no WebP support in the editor engine %s on this system.', $this->editor_engine ) );74 } else {75 $image = $this->resize_helper( $file, 25, 25 ); 76 $this->assertSame( 'test-image-25x25.webp', wp_basename( $image ));77 list($w, $h, $type) = wp_getimagesize( $image);78 $this->assertSame( 25, $w);79 $this->assertSame( 25, $h);80 $this->assertSame( IMAGETYPE_WEBP, $type);81 unlink( $image );82 }73 $this->markTestSkipped( sprintf( 'No WebP support in the editor engine %s on this system.', $this->editor_engine ) ); 74 } 75 76 $image = $this->resize_helper( $file, 25, 25 ); 77 $this->assertSame( 'test-image-25x25.webp', wp_basename( $image ) ); 78 list($w, $h, $type) = wp_getimagesize( $image ); 79 $this->assertSame( 25, $w ); 80 $this->assertSame( 25, $h ); 81 $this->assertSame( IMAGETYPE_WEBP, $type ); 82 unlink( $image ); 83 83 } 84 84
Note: See TracChangeset
for help on using the changeset viewer.