Make WordPress Core


Ignore:
Timestamp:
05/05/2021 05:06:17 PM (5 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r50810 r50814  
    50255025 * @since 5.8.0
    50265026 *
    5027  * @param [type] $filename Path to a WebP file.
     5027 * @param string $filename Path to a WebP file.
    50285028 * @return array $webp_info {
    50295029 *     An array of WebP image information.
    … …  
    50395039        $height = false;
    50405040        $type   = false;
     5041
    50415042        if ( ! 'image/webp' === wp_get_image_mime( $filename ) ) {
    50425043                return compact( 'width', 'height', 'type' );
    50435044        }
     5045
    50445046        try {
    50455047                $handle = fopen( $filename, 'rb' );
    … …  
    50845086        } catch ( Exception $e ) {
    50855087        }
     5088
    50865089        return compact( 'width', 'height', 'type' );
    50875090}
    … …  
    50985101        $webp_info = wp_get_webp_info( $filename );
    50995102        $type      = $webp_info['type'];
     5103
    51005104        return $type && 'lossy' === $type;
    51015105}
    … …  
    51145118        // Try getimagesize() first.
    51155119        $info = getimagesize( $filename, $imageinfo );
     5120
    51165121        if ( false !== $info ) {
    51175122                return $info;
    51185123        }
    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.
    51215127        if ( 'image/webp' === wp_get_image_mime( $filename ) ) {
    51225128                $webp_info = wp_get_webp_info( $filename );
    … …  
    51245130                $height    = $webp_info['height'];
    51255131
    5126                         // Mimic the native return format.
     5132                // Mimic the native return format.
    51275133                if ( $width && $height ) {
    51285134                        return array(
Note: See TracChangeset for help on using the changeset viewer.