Coding Standards: Remove unnecessary try/catch block in `wp_get_webp_info()`.

This appears to be redundant, as none of the functions used inside the block throw an exception.

Follow-up to [50810].

See #54728.
Built from https://develop.svn.wordpress.org/trunk@52717


git-svn-id: http://core.svn.wordpress.org/trunk@52306 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-02-12 13:08:01 +00:00
parent 11691e8207
commit c128cd263a
2 changed files with 40 additions and 40 deletions

View File

@ -5235,47 +5235,47 @@ function wp_get_webp_info( $filename ) {
return compact( 'width', 'height', 'type' ); return compact( 'width', 'height', 'type' );
} }
try { $handle = fopen( $filename, 'rb' );
$handle = fopen( $filename, 'rb' );
if ( $handle ) {
$magic = fread( $handle, 40 );
fclose( $handle );
// Make sure we got enough bytes. if ( false === $handle ) {
if ( strlen( $magic ) < 40 ) { return compact( 'width', 'height', 'type' );
return compact( 'width', 'height', 'type' ); }
}
// The headers are a little different for each of the three formats. $magic = fread( $handle, 40 );
// Header values based on WebP docs, see https://developers.google.com/speed/webp/docs/riff_container. fclose( $handle );
switch ( substr( $magic, 12, 4 ) ) {
// Lossy WebP. // Make sure we got enough bytes.
case 'VP8 ': if ( strlen( $magic ) < 40 ) {
$parts = unpack( 'v2', substr( $magic, 26, 4 ) ); return compact( 'width', 'height', 'type' );
$width = (int) ( $parts[1] & 0x3FFF ); }
$height = (int) ( $parts[2] & 0x3FFF );
$type = 'lossy'; // The headers are a little different for each of the three formats.
break; // Header values based on WebP docs, see https://developers.google.com/speed/webp/docs/riff_container.
// Lossless WebP. switch ( substr( $magic, 12, 4 ) ) {
case 'VP8L': // Lossy WebP.
$parts = unpack( 'C4', substr( $magic, 21, 4 ) ); case 'VP8 ':
$width = (int) ( $parts[1] | ( ( $parts[2] & 0x3F ) << 8 ) ) + 1; $parts = unpack( 'v2', substr( $magic, 26, 4 ) );
$height = (int) ( ( ( $parts[2] & 0xC0 ) >> 6 ) | ( $parts[3] << 2 ) | ( ( $parts[4] & 0x03 ) << 10 ) ) + 1; $width = (int) ( $parts[1] & 0x3FFF );
$type = 'lossless'; $height = (int) ( $parts[2] & 0x3FFF );
break; $type = 'lossy';
// Animated/alpha WebP. break;
case 'VP8X': // Lossless WebP.
// Pad 24-bit int. case 'VP8L':
$width = unpack( 'V', substr( $magic, 24, 3 ) . "\x00" ); $parts = unpack( 'C4', substr( $magic, 21, 4 ) );
$width = (int) ( $width[1] & 0xFFFFFF ) + 1; $width = (int) ( $parts[1] | ( ( $parts[2] & 0x3F ) << 8 ) ) + 1;
// Pad 24-bit int. $height = (int) ( ( ( $parts[2] & 0xC0 ) >> 6 ) | ( $parts[3] << 2 ) | ( ( $parts[4] & 0x03 ) << 10 ) ) + 1;
$height = unpack( 'V', substr( $magic, 27, 3 ) . "\x00" ); $type = 'lossless';
$height = (int) ( $height[1] & 0xFFFFFF ) + 1; break;
$type = 'animated-alpha'; // Animated/alpha WebP.
break; case 'VP8X':
} // Pad 24-bit int.
} $width = unpack( 'V', substr( $magic, 24, 3 ) . "\x00" );
} catch ( Exception $e ) { $width = (int) ( $width[1] & 0xFFFFFF ) + 1;
// Pad 24-bit int.
$height = unpack( 'V', substr( $magic, 27, 3 ) . "\x00" );
$height = (int) ( $height[1] & 0xFFFFFF ) + 1;
$type = 'animated-alpha';
break;
} }
return compact( 'width', 'height', 'type' ); return compact( 'width', 'height', 'type' );

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.0-alpha-52708'; $wp_version = '6.0-alpha-52717';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.