Make WordPress Core


Ignore:
Timestamp:
08/16/2020 01:31:57 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Introduce is_gd_image() to check for PHP 8 GdImage object instances.

In PHP 8, the GD extension uses GdImage objects instead of resources for its underlying data structures.

This updates the existing is_resource() calls for image resources in core to accomodate for GdImage instances as well.

Props ayeshrajans, jrf.
Fixes #50833.

File:
1 edited

Legend:

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

    r48782 r48798  
    34603460 *
    34613461 * @param int $width  Image width in pixels.
    3462  * @param int $height Image height in pixels..
    3463  * @return resource The GD image resource.
     3462 * @param int $height Image height in pixels.
     3463 * @return resource|GdImage The GD image resource or GdImage instance.
    34643464 */
    34653465function wp_imagecreatetruecolor( $width, $height ) {
    34663466    $img = imagecreatetruecolor( $width, $height );
    3467     if ( is_resource( $img ) && function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) {
     3467
     3468    if ( is_gd_image( $img )
     3469        && function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' )
     3470    ) {
    34683471        imagealphablending( $img, false );
    34693472        imagesavealpha( $img, true );
    34703473    }
     3474
    34713475    return $img;
    34723476}
Note: See TracChangeset for help on using the changeset viewer.