WordPress at a glance

file_is_displayable_image() WP 1.0

Validate that file is suitable for displaying within a web page.

✈ 1 time = 0.000001s = speed of light | 50000 times = 0.42s = very fast | PHP 7.2.16, WP 5.1.1
Hooks from the function
Return

true/false. True if suitable, false if not suitable.

Usage

file_is_displayable_image( $path );
$path(string) (required)
File path to test.

Changelog

Since 2.5.0 Introduced.

Code of file is displayable image: wp-admin/includes/image.php WP 5.2.4

<?php
function file_is_displayable_image( $path ) {
	$displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP );

	// IMAGETYPE_ICO is only defined in PHP 5.3+.
	if ( defined( 'IMAGETYPE_ICO' ) ) {
		$displayable_image_types[] = IMAGETYPE_ICO;
	}

	$info = @getimagesize( $path );
	if ( empty( $info ) ) {
		$result = false;
	} elseif ( ! in_array( $info[2], $displayable_image_types ) ) {
		$result = false;
	} else {
		$result = true;
	}

	/**
	 * Filters whether the current image is displayable in the browser.
	 *
	 * @since 2.5.0
	 *
	 * @param bool   $result Whether the image can be displayed. Default true.
	 * @param string $path   Path to the image.
	 */
	return apply_filters( 'file_is_displayable_image', $result, $path );
}

Related Functions

From tag: Files data (get file info)

More from tag: image (not thumbnails funcs)

More from category: Images

No comments
    Hello, !     Log In . Register