wp_getimagesize( string $filename, array $image_info = null )

Allows PHP’s getimagesize() to be debuggable when necessary.


Parameters Parameters

$filename

(string) (Required) The file path.

$image_info

(array) (Optional) Extended image information (passed by reference).

Default value: null


Top ↑

Return Return

(array|false) Array of image information or false on failure.


Top ↑

Source Source

File: wp-includes/media.php

function wp_getimagesize( $filename, array &$image_info = null ) {
	if (
		// Skip when running unit tests.
		! defined( 'WP_RUN_CORE_TESTS' )
		&&
		// Return without silencing errors when in debug mode.
		defined( 'WP_DEBUG' ) && WP_DEBUG
	) {
		if ( 2 === func_num_args() ) {
			return getimagesize( $filename, $image_info );
		} else {
			return getimagesize( $filename );
		}
	}

	/*
	 * 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
		return @getimagesize( $filename, $image_info );
	} else {
		// phpcs:ignore WordPress.PHP.NoSilencedErrors
		return @getimagesize( $filename );
	}
}


Top ↑

Changelog Changelog

Changelog
Version Description
5.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.