Media: Make the `is_gd_image()` function available on front end.

This avoids a fatal error if a plugin calls image creation or editing functions like `wp_imagecreatetruecolor()` outside of the admin.

Follow-up to [48798]

Props BackuPs.
Fixes #51174. See #50833.

git-svn-id: https://develop.svn.wordpress.org/trunk@48905 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-08-28 16:43:31 +00:00
parent 673fcd7927
commit 0013f5979c
2 changed files with 23 additions and 23 deletions

View File

@ -912,29 +912,6 @@ function file_is_displayable_image( $path ) {
return apply_filters( 'file_is_displayable_image', $result, $path );
}
/**
* Determines whether the value is an acceptable type for GD image functions.
*
* In PHP 8.0, the GD extension uses GdImage objects for its data structures.
* This function checks if the passed value is either a resource of type `gd`
* or a GdImage object instance. Any other type will return false.
*
* @since 5.6.0
*
* @param resource|GdImage|false $image A value to check the type for.
* @return bool True if $image is either a GD image resource or GdImage instance,
* false otherwise.
*/
function is_gd_image( $image ) {
if ( is_resource( $image ) && 'gd' === get_resource_type( $image )
|| is_object( $image ) && $image instanceof GdImage
) {
return true;
}
return false;
}
/**
* Load an image resource for editing.
*

View File

@ -3458,6 +3458,29 @@ function get_taxonomies_for_attachments( $output = 'names' ) {
return $taxonomies;
}
/**
* Determines whether the value is an acceptable type for GD image functions.
*
* In PHP 8.0, the GD extension uses GdImage objects for its data structures.
* This function checks if the passed value is either a resource of type `gd`
* or a GdImage object instance. Any other type will return false.
*
* @since 5.6.0
*
* @param resource|GdImage|false $image A value to check the type for.
* @return bool True if $image is either a GD image resource or GdImage instance,
* false otherwise.
*/
function is_gd_image( $image ) {
if ( is_resource( $image ) && 'gd' === get_resource_type( $image )
|| is_object( $image ) && $image instanceof GdImage
) {
return true;
}
return false;
}
/**
* Create new GD image resource with transparency support
*