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

  1. if ( !function_exists( 'file_is_displayable_image' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/image.php'; 
  3.  
  4. // File path to test. 
  5. $path = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = file_is_displayable_image($path); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/image.php  
  1. function file_is_displayable_image($path) { 
  2. $displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP ); 
  3.  
  4. $info = @getimagesize( $path ); 
  5. if ( empty( $info ) ) { 
  6. $result = false; 
  7. } elseif ( ! in_array( $info[2], $displayable_image_types ) ) { 
  8. $result = false; 
  9. } else { 
  10. $result = true; 
  11.  
  12. /** 
  13. * Filters whether the current image is displayable in the browser. 
  14. * @since 2.5.0 
  15. * @param bool $result Whether the image can be displayed. Default true. 
  16. * @param string $path Path to the image. 
  17. */ 
  18. return apply_filters( 'file_is_displayable_image', $result, $path );