Changeset 52717 for trunk/src/wp-includes/media.php
- Timestamp:
- 02/12/2022 01:06:17 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r52425 r52717 5236 5236 } 5237 5237 5238 try {5239 $handle = fopen( $filename, 'rb' ); 5240 if ($handle ) {5241 $magic = fread( $handle, 40);5242 fclose( $handle );5243 5244 // Make sure we got enough bytes.5245 if ( strlen( $magic ) < 40 ) {5246 return compact( 'width', 'height', 'type' ); 5247 }5248 5249 // The headers are a little different for each of the three formats.5250 // Header values based on WebP docs, see https://developers.google.com/speed/webp/docs/riff_container.5251 switch ( substr( $magic, 12, 4 ) ) { 5252 // Lossy WebP.5253 case 'VP8 ':5254 $parts = unpack( 'v2', substr( $magic, 26, 4 ) );5255 $width = (int) ( $parts[1] & 0x3FFF );5256 $height = (int) ( $parts[2] & 0x3FFF );5257 $type = 'lossy';5258 break;5259 // Lossless WebP.5260 case 'VP8L':5261 $parts = unpack( 'C4', substr( $magic, 21, 4 ) );5262 $width = (int) ( $parts[1] | ( ( $parts[2] & 0x3F ) << 8 ) ) + 1;5263 $height = (int) ( ( ( $parts[2] & 0xC0 ) >> 6 ) | ( $parts[3] << 2 ) | ( ( $parts[4] & 0x03 ) << 10 ) ) + 1;5264 $type = 'lossless';5265 break;5266 // Animated/alpha WebP.5267 case 'VP8X':5268 // Pad 24-bit int.5269 $width = unpack( 'V', substr( $magic, 24, 3 ) . "\x00" );5270 $width = (int) ( $width[1] & 0xFFFFFF ) + 1;5271 5272 $height = unpack( 'V', substr( $magic, 27, 3 ) . "\x00" );5273 $height = (int) ( $height[1] & 0xFFFFFF ) + 1;5274 $type = 'animated-alpha';5275 break;5276 }5277 }5278 } catch ( Exception $e ) {5238 $handle = fopen( $filename, 'rb' ); 5239 5240 if ( false === $handle ) { 5241 return compact( 'width', 'height', 'type' ); 5242 } 5243 5244 $magic = fread( $handle, 40 ); 5245 fclose( $handle ); 5246 5247 // Make sure we got enough bytes. 5248 if ( strlen( $magic ) < 40 ) { 5249 return compact( 'width', 'height', 'type' ); 5250 } 5251 5252 // The headers are a little different for each of the three formats. 5253 // Header values based on WebP docs, see https://developers.google.com/speed/webp/docs/riff_container. 5254 switch ( substr( $magic, 12, 4 ) ) { 5255 // Lossy WebP. 5256 case 'VP8 ': 5257 $parts = unpack( 'v2', substr( $magic, 26, 4 ) ); 5258 $width = (int) ( $parts[1] & 0x3FFF ); 5259 $height = (int) ( $parts[2] & 0x3FFF ); 5260 $type = 'lossy'; 5261 break; 5262 // Lossless WebP. 5263 case 'VP8L': 5264 $parts = unpack( 'C4', substr( $magic, 21, 4 ) ); 5265 $width = (int) ( $parts[1] | ( ( $parts[2] & 0x3F ) << 8 ) ) + 1; 5266 $height = (int) ( ( ( $parts[2] & 0xC0 ) >> 6 ) | ( $parts[3] << 2 ) | ( ( $parts[4] & 0x03 ) << 10 ) ) + 1; 5267 $type = 'lossless'; 5268 break; 5269 // Animated/alpha WebP. 5270 case 'VP8X': 5271 // Pad 24-bit int. 5272 $width = unpack( 'V', substr( $magic, 24, 3 ) . "\x00" ); 5273 $width = (int) ( $width[1] & 0xFFFFFF ) + 1; 5274 // Pad 24-bit int. 5275 $height = unpack( 'V', substr( $magic, 27, 3 ) . "\x00" ); 5276 $height = (int) ( $height[1] & 0xFFFFFF ) + 1; 5277 $type = 'animated-alpha'; 5278 break; 5279 5279 } 5280 5280
Note: See TracChangeset
for help on using the changeset viewer.