get_intermediate_image_sizes(): string[]

Gets the available intermediate image size names.

Return

string[] An array of image size names.

More Information

Details of returned value.

var_dump( get_intermediate_image_sizes() );
  array(4) {
    [0]=>
    string(9) "thumbnail"
    [1]=>
    string(6) "medium"
    [2]=>
    string(12) "medium_large"
    [3]=>
    string(5) "large"
    [4]=>
    string(10) "custom-size"
  }

Source

function get_intermediate_image_sizes() {
	$default_sizes    = array( 'thumbnail', 'medium', 'medium_large', 'large' );
	$additional_sizes = wp_get_additional_image_sizes();

	if ( ! empty( $additional_sizes ) ) {
		$default_sizes = array_merge( $default_sizes, array_keys( $additional_sizes ) );
	}

	/**
	 * Filters the list of intermediate image sizes.
	 *
	 * @since 2.5.0
	 *
	 * @param string[] $default_sizes An array of intermediate image size names. Defaults
	 *                                are 'thumbnail', 'medium', 'medium_large', 'large'.
	 */
	return apply_filters( 'intermediate_image_sizes', $default_sizes );
}

Hooks

apply_filters( ‘intermediate_image_sizes’, string[] $default_sizes )

Filters the list of intermediate image sizes.

Changelog

VersionDescription
3.0.0Introduced.

User Contributed Notes

  1. Skip to note 4 content

    List available image sizes with width and height following

    /**
     * Get information about available image sizes
     */
    function get_image_sizes( $size = '' ) {
    	$wp_additional_image_sizes = wp_get_additional_image_sizes();
    
    	$sizes = array();
    	$get_intermediate_image_sizes = get_intermediate_image_sizes();
    
    	// Create the full array with sizes and crop info
    	foreach( $get_intermediate_image_sizes as $_size ) {
    		if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ) ) ) {
    			$sizes[ $_size ]['width'] = get_option( $_size . '_size_w' );
    			$sizes[ $_size ]['height'] = get_option( $_size . '_size_h' );
    			$sizes[ $_size ]['crop'] = (bool) get_option( $_size . '_crop' );
    		} elseif ( isset( $wp_additional_image_sizes[ $_size ] ) ) {
    			$sizes[ $_size ] = array( 
    				'width' => $wp_additional_image_sizes[ $_size ]['width'],
    				'height' => $wp_additional_image_sizes[ $_size ]['height'],
    				'crop' =>  $wp_additional_image_sizes[ $_size ]['crop']
    			);
    		}
    	}
    
    	// Get only 1 size if found
    	if ( $size ) {
    		if( isset( $sizes[ $size ] ) ) {
    			return $sizes[ $size ];
    		} else {
    			return false;
    		}
    	}
    	return $sizes;
    }

    Some examples of use of this function:

    var_dump( get_image_sizes() );
    /*
    array(4) {
      ["thumbnail"]=>
      array(3) {
        ["width"]=>
        string(3) "150"
        ["height"]=>
        string(3) "150"
        ["crop"]=>
        bool(true)
      }
      ["medium"]=>
      array(3) {
        ["width"]=>
        string(3) "300"
        ["height"]=>
        string(3) "300"
        ["crop"]=>
        bool(false)
      }
      ["large"]=>
      array(3) {
        ["width"]=>
        string(4) "1024"
        ["height"]=>
        string(4) "1024"
        ["crop"]=>
        bool(false)
      }
      ["juliobox-size"]=>
      array(3) {
        ["width"]=>
        int(211)
        ["height"]=>
        int(279)
        ["crop"]=>
        bool(false)
      }
    }
    */
    
    var_dump( get_image_sizes( 'large' ) );
    /*
    array(3) {
      ["width"]=>
      int(1024)
      ["height"]=>
      int(1024)
      ["crop"]=>
      bool(false)
    }
    */
    
    var_dump( get_image_sizes( 'foo-bar' ) );
    /*
    bool(false)
    */
  2. Skip to note 6 content

    Get all possible registered image size with their names

    $wp_additional_image_sizes = wp_get_additional_image_sizes();
    
    $sizes = array();
    $get_intermediate_image_sizes = get_intermediate_image_sizes();
    
    // Create the full array with sizes and crop info
    foreach ( $get_intermediate_image_sizes as $_size ) {
      if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ) ) ) {
        $sizes[ $_size ]['width'] = get_option( $_size . '_size_w' );
        $sizes[ $_size ]['height'] = get_option( $_size . '_size_h' );
        $sizes[ $_size ]['crop'] = (bool) get_option( $_size . '_crop' );
      } elseif ( isset( $wp_additional_image_sizes[ $_size ] ) ) {
        $sizes[ $_size ] = array(
          'width' => $wp_additional_image_sizes[ $_size ]['width'],
          'height' => $wp_additional_image_sizes[ $_size ]['height'],
          'crop' =>  $wp_additional_image_sizes[ $_size ]['crop']
        );
      }
    }
    foreach ( $sizes as $key => $image_size ) {
      echo  '<li>' . $key . ' ' . $image_size['width'] . ' x ' . $image_size['height'] . ' ' . $image_size['crop'] . '</li>';
    }

You must log in before being able to contribute a note or feedback.