Media: Some documentation and test improvements for WebP support:
* Document that WebP constants are only defined in PHP 7.1+. * Correct the `$filename` parameter type in `wp_get_webp_info()`. * Use a consistent message when skipping tests due to the lack of WebP support. * Remove unnecessary `else` branches after `markTestSkipped()`. * Replace `assertEquals()` with more appropriate assertions. Follow-up to [50810]. See #35725. Built from https://develop.svn.wordpress.org/trunk@50814 git-svn-id: http://core.svn.wordpress.org/trunk@50423 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e21dfba663
commit
0778849c12
|
@ -371,7 +371,7 @@ if ( ! function_exists( 'is_iterable' ) ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebP constants may not be defined, even in cases where the format is supported.
|
// WebP constants are only defined in PHP 7.1+.
|
||||||
if ( ! defined( 'IMAGETYPE_WEBP' ) ) {
|
if ( ! defined( 'IMAGETYPE_WEBP' ) ) {
|
||||||
define( 'IMAGETYPE_WEBP', 18 );
|
define( 'IMAGETYPE_WEBP', 18 );
|
||||||
}
|
}
|
||||||
|
|
|
@ -3079,9 +3079,11 @@ function wp_get_image_mime( $file ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add WebP fallback detection when image library doesn't support WebP.
|
/*
|
||||||
// Note: detection values come from LibWebP, see
|
* Add WebP fallback detection when image library doesn't support WebP.
|
||||||
// https://github.com/webmproject/libwebp/blob/master/imageio/image_dec.c#L30
|
* Note: detection values come from LibWebP, see
|
||||||
|
* https://github.com/webmproject/libwebp/blob/master/imageio/image_dec.c#L30
|
||||||
|
*/
|
||||||
$magic = bin2hex( $magic );
|
$magic = bin2hex( $magic );
|
||||||
if (
|
if (
|
||||||
// RIFF.
|
// RIFF.
|
||||||
|
|
|
@ -5024,7 +5024,7 @@ function wp_getimagesize( $filename, array &$image_info = null ) {
|
||||||
*
|
*
|
||||||
* @since 5.8.0
|
* @since 5.8.0
|
||||||
*
|
*
|
||||||
* @param [type] $filename Path to a WebP file.
|
* @param string $filename Path to a WebP file.
|
||||||
* @return array $webp_info {
|
* @return array $webp_info {
|
||||||
* An array of WebP image information.
|
* An array of WebP image information.
|
||||||
*
|
*
|
||||||
|
@ -5038,9 +5038,11 @@ function wp_get_webp_info( $filename ) {
|
||||||
$width = false;
|
$width = false;
|
||||||
$height = false;
|
$height = false;
|
||||||
$type = false;
|
$type = false;
|
||||||
|
|
||||||
if ( ! 'image/webp' === wp_get_image_mime( $filename ) ) {
|
if ( ! 'image/webp' === wp_get_image_mime( $filename ) ) {
|
||||||
return compact( 'width', 'height', 'type' );
|
return compact( 'width', 'height', 'type' );
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$handle = fopen( $filename, 'rb' );
|
$handle = fopen( $filename, 'rb' );
|
||||||
if ( $handle ) {
|
if ( $handle ) {
|
||||||
|
@ -5083,6 +5085,7 @@ function wp_get_webp_info( $filename ) {
|
||||||
}
|
}
|
||||||
} catch ( Exception $e ) {
|
} catch ( Exception $e ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return compact( 'width', 'height', 'type' );
|
return compact( 'width', 'height', 'type' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5097,6 +5100,7 @@ function wp_get_webp_info( $filename ) {
|
||||||
function _wp_webp_is_lossy( $filename ) {
|
function _wp_webp_is_lossy( $filename ) {
|
||||||
$webp_info = wp_get_webp_info( $filename );
|
$webp_info = wp_get_webp_info( $filename );
|
||||||
$type = $webp_info['type'];
|
$type = $webp_info['type'];
|
||||||
|
|
||||||
return $type && 'lossy' === $type;
|
return $type && 'lossy' === $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5113,17 +5117,19 @@ function _wp_webp_is_lossy( $filename ) {
|
||||||
function _wp_get_image_size( $filename, &$imageinfo = array() ) {
|
function _wp_get_image_size( $filename, &$imageinfo = array() ) {
|
||||||
// Try getimagesize() first.
|
// Try getimagesize() first.
|
||||||
$info = getimagesize( $filename, $imageinfo );
|
$info = getimagesize( $filename, $imageinfo );
|
||||||
|
|
||||||
if ( false !== $info ) {
|
if ( false !== $info ) {
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
// For PHP versions that don't support WebP images, extract the image
|
|
||||||
// size info from the file headers.
|
// For PHP versions that don't support WebP images,
|
||||||
|
// extract the image size info from the file headers.
|
||||||
if ( 'image/webp' === wp_get_image_mime( $filename ) ) {
|
if ( 'image/webp' === wp_get_image_mime( $filename ) ) {
|
||||||
$webp_info = wp_get_webp_info( $filename );
|
$webp_info = wp_get_webp_info( $filename );
|
||||||
$width = $webp_info['width'];
|
$width = $webp_info['width'];
|
||||||
$height = $webp_info['height'];
|
$height = $webp_info['height'];
|
||||||
|
|
||||||
// Mimic the native return format.
|
// Mimic the native return format.
|
||||||
if ( $width && $height ) {
|
if ( $width && $height ) {
|
||||||
return array(
|
return array(
|
||||||
$width,
|
$width,
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.8-alpha-50813';
|
$wp_version = '5.8-alpha-50814';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
|
Loading…
Reference in New Issue