WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get intermediate image sizes

Description

Get the available image sizes

Usage

<?php get_intermediate_image_sizes(); ?>

Return Values

(array) 
Returns a filtered array of image size strings

Demo

var_dump( get_intermediate_image_sizes() );

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

Examples

List available image sizes with width and height following

function get_image_sizes( $size = '' ) {

        global $_wp_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:

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

Change Log

Since: 3.0

Source File

get_intermediate_image_sizes() is located in wp-includes/media.php