Skip to content

Instantly share code, notes, and snippets.

@dannyconnolly
Created December 12, 2018 10:33
Show Gist options
  • Save dannyconnolly/a9d5840220cbcb821504c9108575a9e6 to your computer and use it in GitHub Desktop.
Save dannyconnolly/a9d5840220cbcb821504c9108575a9e6 to your computer and use it in GitHub Desktop.
/**
* Get information about available image sizes
*/
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment