Print WordPress Registered Image Sizes Selection Box
<?php
/* Query the blog library for an image and return it's ID */
function fcc_image_id() {
$query_images_args = array(
'post_type' => 'attachment', 'post_mime_type' =>'image', 'post_status' => 'inherit', 'posts_per_page' => 1, //'order' => 'ASC',
);
$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image) {
$images[]= wp_get_attachment_url( $image->ID );
}
$image_url = $images[0];
$image_id = fcc_get_image_id($image_url);
return $image_id;
}
/* retrieves the attachment ID from the file URL */
function fcc_get_image_id($image_url) {
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
return $attachment[0];
}
/*
* Print a Image Size Drop-down Selection Box
*/
global $_wp_additional_image_sizes;
global $post;
$post_id = fcc_image_id(); //Attachment ID for image.
$image_sizes = array(); //blank
$standard_image_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes
if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
$additional_image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
$image_sizes = array_merge( $standard_image_sizes, $additional_image_sizes );
//Print Selection Box//
echo '<select name="image_size">';
foreach ($image_sizes as $size_name):
$get_sizes = image_get_intermediate_size($post_id , $size_name );
$width = $get_sizes['width'];
$height = $get_sizes['height'];
echo '<option value="' . $size_name . '">';
echo ucwords( $size_name ) . ': ' . $width . ' x ' . $height;
echo '</option>';
endforeach;
echo '</select>';