WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/get intermediate image sizes

Contents

Description

Get the available image sizes

Usage

<?php get_intermediate_image_sizes(); ?>

Return Values

(array) 
Returns a filtered array of image size strings

Examples

List available image sizes with width and height following

 function list_thumbnail_sizes(){
     global $_wp_additional_image_sizes;
     	$sizes = array();
 		foreach( get_intermediate_image_sizes() as $s ){
 			$sizes[ $s ] = array( 0, 0 );
 			if( in_array( $s, array( 'thumbnail', 'medium', 'large' ) ) ){
 				$sizes[ $s ][0] = get_option( $s . '_size_w' );
 				$sizes[ $s ][1] = get_option( $s . '_size_h' );
 			}else{
 				if( isset( $_wp_additional_image_sizes ) && isset( $_wp_additional_image_sizes[ $s ] ) )
 					$sizes[ $s ] = array( $_wp_additional_image_sizes[ $s ]['width'], $_wp_additional_image_sizes[ $s ]['height'], );
 			}
 		}
 
 		foreach( $sizes as $size => $atts ){
 			echo $size . ' ' . implode( 'x', $atts ) . "\n";
 		}
 }
 
 list_thumbnail_sizes();
 // thumbnail 150x150
 // medium 300x300
 // large 1024x1024

PLEASE NOTE: Limited testing in 3.6 show that the above code isn't 100% accurate.

Specifically, if you use add_image_size() to define your own version of 'medium' WP will use your version, not the values for 'medium' stored in the options table. {Whether this is true for thumbnails and some of the thumbnail specific functions has not yet been investigated.)

This is a valuable "feature" if you don't want your Settings > Media image sizes to be subject to random / unintentional changes. That is, code based image size defitions will override those defined in options. (Or so it seems.)

Change Log

Since: 3.0

Source File

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