file_is_displayable_image
Validate that file is suitable for displaying within a web page.
Description
file_is_displayable_image( (string) $path );
Parameters (1)
- 0. $path (string)
- File path to test.
Usage
if ( !function_exists( 'file_is_displayable_image' ) ) { require_once ABSPATH . '/wp-admin/includes/image.php'; } // File path to test. $path = ''; // NOTICE! Understand what this does before running. $result = file_is_displayable_image($path);
Defined (1)
The function is defined in the following location(s).
- /wp-admin/includes/image.php
- function file_is_displayable_image($path) {
- $displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP );
- $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 );
- }