WordPress' get intermediate image sizes() function is used to "get the available image sizes". The functions below, from the WP Codex , are a handy reference for dealing with available sizes. the following function will list available image sizes with width and height following.
The snippets are included to support the article "Import Remote Images into WordPress and Return Image URL, Image ID, and Image Dimensions" on this page.
1
<?php
2
/*
3
Get size information for all currently-registered image sizes.
4
@global $_wp_additional_image_sizes
5
@uses get_intermediate_image_sizes()
6
@return array $sizes Data for all currently-registered image sizes.
7
*/
8
9
function get_image_sizes() {
10
11
global $_wp_additional_image_sizes;
12
$sizes = array();
13
14
15
16
17
18
19
} elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
20
$sizes[ $_size ] = array(
21
'width' => $_wp_additional_image_sizes[ $_size ]['width'],
22
'height' => $_wp_additional_image_sizes[ $_size ]['height'],
23
'crop' => $_wp_additional_image_sizes[ $_size ]['crop'],
24
);
25
}
26
}
27
28
return $sizes;
29
}
30
31
/*
32
Get size information for a specific image size.
33
@uses get_image_sizes()
34
@param string $size The image size for which to retrieve data.
35
@return bool|array $size Size data about an image size or false if the size doesn't exist.
36
*/
37
38
function get_image_size( $size ) {
39
$sizes = get_image_sizes();
40
if ( isset( $sizes[ $size ] ) ) return $sizes[ $size ];
41
else return false;
42
}
43
44
/*
45
Get the width of a specific image size.
46
@uses get_image_size()
47
@param string $size The image size for which to retrieve data.
48
@return bool|string $size Width of an image size or false if the size doesn't exist.
49
*/
50
51
function get_image_width( $size ) {
52
if ( ! $size = get_image_size( $size ) ) return false;
53
if ( isset( $size['width'] ) ) return $size['width'];
54
55
return false;
56
}
57
58
/*
59
Get the height of a specific image size.
60
@uses get_image_size()
61
@param string $size The image size for which to retrieve data.
62
@return bool|string $size Height of an image size or false if the size doesn't exist.
63
*/
64
65
function get_image_height( $size ) {
66
if ( ! $size = get_image_size( $size ) ) return false;
67
if ( isset( $size['height'] ) ) return $size['height'];
68
69
return false;
70
}