get_intermediate_image_sizes()

Gets the available intermediate image sizes.


Description Description


Return Return

(array) Returns a filtered array of image size strings.


Top ↑

Source Source

File: wp-includes/media.php

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 array $default_sizes An array of intermediate image sizes. Defaults
	 *                             are 'thumbnail', 'medium', 'medium_large', 'large'.
	 */
	return apply_filters( 'intermediate_image_sizes', $default_sizes );
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 2 content
    Contributed by Codex

    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)
    */
    
    

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