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.
Built from https://develop.svn.wordpress.org/trunk@48798


git-svn-id: http://core.svn.wordpress.org/trunk@48560 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2020-08-16 13:33:09 +00:00
parent a5edb2a8a1
commit 12c8f0e678
7 changed files with 95 additions and 51 deletions

View File

@@ -3196,7 +3196,8 @@ function _get_post_ancestors( &$post ) {
* @see wp_get_image_editor()
*
* @param string $file Filename of the image to load.
* @return resource The resulting image resource on success, Error string on failure.
* @return resource|GdImage|string The resulting image resource or GdImage instance on success,
* error string on failure.
*/
function wp_load_image( $file ) {
_deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' );
@@ -3217,7 +3218,7 @@ function wp_load_image( $file ) {
$image = imagecreatefromstring( file_get_contents( $file ) );
if ( ! is_resource( $image ) ) {
if ( ! is_gd_image( $image ) ) {
/* translators: %s: File name. */
return sprintf( __( 'File “%s” is not an image.' ), $file );
}