On this page
wp_getimagesize( string $filename, array $image_info = null ): array|false
Allows PHP’s getimagesize() to be debuggable when necessary.
Parameters
$filenamestring Required-
The file path.
$image_infoarray Optional-
Extended image information (passed by reference).
Default:
null
Return
array|false Array of image information or false on failure.
Source
File: wp-includes/media.php. View all references
function wp_getimagesize( $filename, array &$image_info = null ) {
// 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() ) {
$info = getimagesize( $filename, $image_info );
} else {
$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 );
}
}
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,
sprintf(
'width="%d" height="%d"',
$width,
$height
),
'mime' => 'image/webp',
);
}
}
// The image could not be parsed.
return false;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_get_webp_info() wp-includes/media.php | Extracts meta information about a WebP file: width, height, and type. |
| wp_get_image_mime() wp-includes/functions.php | Returns the real mime type of an image file. |
Used By
| Used By | Description |
|---|---|
| wp_get_missing_image_subsizes() wp-admin/includes/image.php | Compare the existing image sub-sizes (as saved in the attachment meta) to the currently registered image sub-sizes, and return the difference. |
| wp_create_image_subsizes() wp-admin/includes/image.php | Creates image sub-sizes, adds the new data to the image meta |
| WP_Site_Icon::create_attachment_object() wp-admin/includes/class-wp-site-icon.php | Creates an attachment ‘object’. |
| wp_ajax_crop_image() wp-admin/includes/ajax-actions.php | Ajax handler for cropping an image. |
| wp_read_image_metadata() wp-admin/includes/image.php | Gets extended image metadata, exif or iptc as available. |
| file_is_valid_image() wp-admin/includes/image.php | Validates that file is an image. |
| file_is_displayable_image() wp-admin/includes/image.php | Validates that file is suitable for displaying within a web page. |
| Custom_Image_Header::create_attachment_object() wp-admin/includes/class-custom-image-header.php | Create an attachment ‘object’. |
| Custom_Image_Header::step_2() wp-admin/includes/class-custom-image-header.php | Display second step of custom header image page. |
| get_attachment_icon() wp-includes/deprecated.php | Retrieve HTML content of icon attachment image element. |
| WP_Image_Editor_GD::load() wp-includes/class-wp-image-editor-gd.php | Loads image from $this->file into new GD Resource. |
| wp_get_attachment_image_src() wp-includes/media.php | Retrieves an image to represent an attachment. |
| image_downsize() wp-includes/media.php | Scales an image to fit a particular size (such as ‘thumb’ or ‘medium’). |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_getimagesize