wp_load_image

Load an image from a string, if PHP supports it.

Description

(resource) wp_load_image( (string) $file ); 

Returns (resource)

The resulting image resource on success, Error string on failure.

Parameters (1)

0. $file (string)
Filename of the image to load.

Usage

  1. if ( !function_exists( 'wp_load_image' ) ) { 
  2. require_once ABSPATH . WPINC . '/deprecated.php'; 
  3.  
  4. // Filename of the image to load. 
  5. $file = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_load_image($file); 
  9.  

Defined (1)

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

/wp-includes/deprecated.php  
  1. function wp_load_image( $file ) { 
  2. _deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' ); 
  3.  
  4. if ( is_numeric( $file ) ) 
  5. $file = get_attached_file( $file ); 
  6.  
  7. if ( ! is_file( $file ) ) { 
  8. /** translators: %s: file name */ 
  9. return sprintf( __( 'File “%s” doesn’t exist?' ), $file ); 
  10.  
  11. if ( ! function_exists('imagecreatefromstring') ) 
  12. return __('The GD image library is not installed.'); 
  13.  
  14. // Set artificially high because GD uses uncompressed images in memory. 
  15. wp_raise_memory_limit( 'image' ); 
  16.  
  17. $image = imagecreatefromstring( file_get_contents( $file ) ); 
  18.  
  19. if ( ! is_resource( $image ) ) { 
  20. /** translators: %s: file name */ 
  21. return sprintf( __( 'File “%s” is not an image.' ), $file ); 
  22.  
  23. return $image;