add_image_size

Register a new image size.

Description

add_image_size( (string) $name, (int) $width = 0, (int) $height = 0, (bool) $crop = false ); 

Cropping behavior for the image size is dependent on the value of $crop: 1. If false (default), images will be scaled, not cropped. 2. If an array in the form of array( x_crop_position, y_crop_position ): 3. If true, images will be cropped to the specified dimensions using center positions.

Parameters (4)

0. $name (string)
Image size identifier.
1. $width — Optional. (int)
Image width in pixels.
2. $height — Optional. (int)
Image height in pixels.
3. $crop — Optional. (bool) => false
Whether to crop images to specified width and height or resize. An array can specify positioning of the crop area. Default false.

Usage

  1. if ( !function_exists( 'add_image_size' ) ) { 
  2. require_once ABSPATH . WPINC . '/media.php'; 
  3.  
  4. // Image size identifier. 
  5. $name = ''; 
  6.  
  7. // Image width in pixels. 
  8. $width = -1; 
  9.  
  10. // Image height in pixels. 
  11. $height = -1; 
  12.  
  13. // Optional. Whether to crop images to specified width and height or resize. 
  14. // An array can specify positioning of the crop area. Default false. 
  15. $crop = false; 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = add_image_size($name, $width, $height, $crop); 
  19.  

Defined (1)

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

/wp-includes/media.php  
  1. function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { 
  2. global $_wp_additional_image_sizes; 
  3.  
  4. $_wp_additional_image_sizes[ $name ] = array( 
  5. 'width' => absint( $width ),  
  6. 'height' => absint( $height ),  
  7. 'crop' => $crop,  
  8. );