Media: Move retrieving WebP image size information into `wp_getimagesize()`.
Remove `_wp_get_image_size()`. Follow-up to [50146], [50810], [50814]. Props johnjamesjacoby. See #35725. Built from https://develop.svn.wordpress.org/trunk@50815 git-svn-id: http://core.svn.wordpress.org/trunk@50424 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0778849c12
commit
16c42e467d
|
@ -723,12 +723,9 @@ function wp_read_image_metadata( $file ) {
|
|||
wp_getimagesize( $file, $info );
|
||||
|
||||
if ( ! empty( $info['APP13'] ) ) {
|
||||
if (
|
||||
// Skip when running unit tests.
|
||||
! defined( 'WP_RUN_CORE_TESTS' )
|
||||
&&
|
||||
// Process without silencing errors when in debug mode.
|
||||
defined( 'WP_DEBUG' ) && WP_DEBUG
|
||||
// Don't silence errors when in debug mode, unless running unit tests.
|
||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG
|
||||
&& ! defined( 'WP_RUN_CORE_TESTS' )
|
||||
) {
|
||||
$iptc = iptcparse( $info['APP13'] );
|
||||
} else {
|
||||
|
@ -794,12 +791,9 @@ function wp_read_image_metadata( $file ) {
|
|||
$exif_image_types = apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) );
|
||||
|
||||
if ( is_callable( 'exif_read_data' ) && in_array( $image_type, $exif_image_types, true ) ) {
|
||||
if (
|
||||
// Skip when running unit tests.
|
||||
! defined( 'WP_RUN_CORE_TESTS' )
|
||||
&&
|
||||
// Process without silencing errors when in debug mode.
|
||||
defined( 'WP_DEBUG' ) && WP_DEBUG
|
||||
// Don't silence errors when in debug mode, unless running unit tests.
|
||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG
|
||||
&& ! defined( 'WP_RUN_CORE_TESTS' )
|
||||
) {
|
||||
$exif = exif_read_data( $file );
|
||||
} else {
|
||||
|
|
|
@ -4987,36 +4987,63 @@ function wp_show_heic_upload_error( $plupload_settings ) {
|
|||
* @return array|false Array of image information or false on failure.
|
||||
*/
|
||||
function wp_getimagesize( $filename, array &$image_info = null ) {
|
||||
if (
|
||||
// Skip when running unit tests.
|
||||
! defined( 'WP_RUN_CORE_TESTS' )
|
||||
&&
|
||||
// Return without silencing errors when in debug mode.
|
||||
defined( 'WP_DEBUG' ) && WP_DEBUG
|
||||
// Don't silence errors when in debug mode, unless running unit tests.
|
||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG
|
||||
&& ! defined( 'WP_RUN_CORE_TESTS' )
|
||||
) {
|
||||
if ( 2 === func_num_args() ) {
|
||||
return _wp_get_image_size( $filename, $image_info );
|
||||
$info = getimagesize( $filename, $image_info );
|
||||
} else {
|
||||
return _wp_get_image_size( $filename );
|
||||
$info = getimagesize( $filename );
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Silencing notice and warning is intentional.
|
||||
*
|
||||
* getimagesize() has a tendency to generate errors, such as
|
||||
* "corrupt JPEG data: 7191 extraneous bytes before marker",
|
||||
* even when it's able to provide image size information.
|
||||
*
|
||||
* See https://core.trac.wordpress.org/ticket/42480
|
||||
*/
|
||||
if ( 2 === func_num_args() ) {
|
||||
// phpcs:ignore WordPress.PHP.NoSilencedErrors
|
||||
$info = @getimagesize( $filename, $image_info );
|
||||
} else {
|
||||
// phpcs:ignore WordPress.PHP.NoSilencedErrors
|
||||
$info = @getimagesize( $filename );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Silencing notice and warning is intentional.
|
||||
*
|
||||
* getimagesize() has a tendency to generate errors, such as
|
||||
* "corrupt JPEG data: 7191 extraneous bytes before marker",
|
||||
* even when it's able to provide image size information.
|
||||
*
|
||||
* See https://core.trac.wordpress.org/ticket/42480
|
||||
*/
|
||||
if ( 2 === func_num_args() ) {
|
||||
// phpcs:ignore WordPress.PHP.NoSilencedErrors
|
||||
return @_wp_get_image_size( $filename, $image_info );
|
||||
} else {
|
||||
// phpcs:ignore WordPress.PHP.NoSilencedErrors
|
||||
return @_wp_get_image_size( $filename );
|
||||
if ( false !== $info ) {
|
||||
return $info;
|
||||
}
|
||||
|
||||
// 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 ) ) {
|
||||
$webp_info = wp_get_webp_info( $filename );
|
||||
$width = $webp_info['width'];
|
||||
$height = $webp_info['height'];
|
||||
|
||||
// Mimic the native return format.
|
||||
if ( $width && $height ) {
|
||||
return array(
|
||||
$width,
|
||||
$height,
|
||||
IMAGETYPE_WEBP, // phpcs:ignore PHPCompatibility.Constants.NewConstants.imagetype_webpFound
|
||||
sprintf(
|
||||
'width="%d" height="%d"',
|
||||
$width,
|
||||
$height
|
||||
),
|
||||
'mime' => 'image/webp',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// The image could not be parsed.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5103,48 +5130,3 @@ function _wp_webp_is_lossy( $filename ) {
|
|||
|
||||
return $type && 'lossy' === $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the image size, with support for WebP images.
|
||||
*
|
||||
* @since 5.8.0
|
||||
* @access private
|
||||
*
|
||||
* @param string $filename The file path.
|
||||
* @param array $imageinfo Extended image information, passed by reference.
|
||||
* @return array|false Array of image information or false on failure.
|
||||
*/
|
||||
function _wp_get_image_size( $filename, &$imageinfo = array() ) {
|
||||
// Try getimagesize() first.
|
||||
$info = getimagesize( $filename, $imageinfo );
|
||||
|
||||
if ( false !== $info ) {
|
||||
return $info;
|
||||
}
|
||||
|
||||
// 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 ) ) {
|
||||
$webp_info = wp_get_webp_info( $filename );
|
||||
$width = $webp_info['width'];
|
||||
$height = $webp_info['height'];
|
||||
|
||||
// Mimic the native return format.
|
||||
if ( $width && $height ) {
|
||||
return array(
|
||||
$width,
|
||||
$height,
|
||||
IMAGETYPE_WEBP, // phpcs:ignore PHPCompatibility.Constants.NewConstants.imagetype_webpFound
|
||||
sprintf(
|
||||
'width="%d" height="%d"',
|
||||
$width,
|
||||
$height
|
||||
),
|
||||
'mime' => 'image/webp',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// The image could not be parsed.
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.8-alpha-50814';
|
||||
$wp_version = '5.8-alpha-50815';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue