image_make_intermediate_size

Resizes an image to make a thumbnail or intermediate size.

Description

(false|array) image_make_intermediate_size( (string) $file, (int) $width, (int) $height, (bool) $crop = false ); 

The returned array has the file size, the image width, and image height. The filter can be used to hook in and change the values of the returned array. The only parameter is the resized file path.

Returns (false|array)

False, if no image was created. Metadata array on success.

Parameters (4)

0. $file (string)
File path.
1. $width (int)
Image width.
2. $height (int)
Image height.
3. $crop — Optional. (bool) => false
Whether to crop image to specified width and height or resize. Default false.

Usage

  1. if ( !function_exists( 'image_make_intermediate_size' ) ) { 
  2. require_once ABSPATH . WPINC . '/media.php'; 
  3.  
  4. // File path. 
  5. $file = ''; 
  6.  
  7. // Image width. 
  8. $width = -1; 
  9.  
  10. // Image height. 
  11. $height = -1; 
  12.  
  13. // Optional. Whether to crop image to specified width and height or resize. 
  14. // Default false. 
  15. $crop = false; 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = image_make_intermediate_size($file, $width, $height, $crop); 
  19.  

Defined (1)

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

/wp-includes/media.php  
  1. function image_make_intermediate_size( $file, $width, $height, $crop = false ) { 
  2. if ( $width || $height ) { 
  3. $editor = wp_get_image_editor( $file ); 
  4.  
  5. if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) 
  6. return false; 
  7.  
  8. $resized_file = $editor->save(); 
  9.  
  10. if ( ! is_wp_error( $resized_file ) && $resized_file ) { 
  11. unset( $resized_file['path'] ); 
  12. return $resized_file; 
  13. return false;