Index: wp-includes/media.php
===================================================================
--- wp-includes/media.php	(revision 22833)
+++ wp-includes/media.php	(working copy)
@@ -1331,26 +1331,25 @@
 
 	if ( $meta && 'image' === $type ) {
 		$sizes = array();
-		$base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url );
+		$possible_sizes = apply_filters( 'image_size_names_choose', array(
+			'thumbnail' => __('Thumbnail'),
+			'medium'    => __('Medium'),
+			'large'     => __('Large'),
+			'full'      => __('Full Size'),
+		) );
 
-		if ( isset( $meta['sizes'] ) ) {
-			foreach ( $meta['sizes'] as $slug => $size ) {
-				$sizes[ $slug ] = array(
-					'height'      => $size['height'],
-					'width'       => $size['width'],
-					'url'         => $base_url . $size['file'],
-					'orientation' => $size['height'] > $size['width'] ? 'portrait' : 'landscape',
+		foreach ( $possible_sizes as $size => $label ) {
+			$downsize = image_downsize( $attachment->ID, $size );
+			if ( 'full' == $size || $downsize[3] ) {
+				$sizes[ $size ] = array(
+					'height'      => $downsize[2],
+					'width'       => $downsize[1],
+					'url'         => $downsize[0],
+					'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape',
 				);
 			}
 		}
 
-		$sizes['full'] = array(
-			'height'      => $meta['height'],
-			'width'       => $meta['width'],
-			'url'         => $attachment_url,
-			'orientation' => $meta['height'] > $meta['width'] ? 'portrait' : 'landscape',
-		);
-
 		$response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] );
 	}
 
