Index: wp-includes/media.php
===================================================================
--- wp-includes/media.php	(revision 18627)
+++ wp-includes/media.php	(working copy)
@@ -528,9 +528,18 @@
 
 	// get the best one for a specified set of dimensions
 	if ( is_array($size) && !empty($imagedata['sizes']) ) {
+		// sort $imagemeta['sizes'] descending by width, height
+		uasort( $imagedata['sizes'], '_compare_imagedata_sizes' );
+		// loop through $imagemeta['sizes'] to find the right thumbnail size
 		foreach ( $imagedata['sizes'] as $_size => $data ) {
+			// already cropped exactly to width and height; so use this size
+			if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) {
+				$file = $data['file'];
+				list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
+				return compact( 'file', 'width', 'height' );
+			}
 			// already cropped to width or height; so use this size
-			if ( ( $data['width'] == $size[0] && $data['height'] <= $size[1] ) || ( $data['height'] == $size[1] && $data['width'] <= $size[0] ) ) {
+			elseif ( ( $data['width'] == $size[0] && $data['height'] <= $size[1] ) || ( $data['height'] == $size[1] && $data['width'] <= $size[0] ) ) {
 				$file = $data['file'];
 				list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
 				return compact( 'file', 'width', 'height' );
@@ -573,6 +582,20 @@
 }
 
 /**
+ * Callback to sort $imagemeta['sizes'] descending by width, height
+ *
+ * @since 3.1.0
+ * @access private
+ */
+function _compare_imagedata_sizes( $a, $b ) {
+	$sorted = strnatcmp( $a['width'], $b['width'] );
+	if ( ! $sorted )
+		return strnatcmp( $a['height'], $b['height'] );
+	array_reverse( $sorted );
+	return $sorted;
+}
+
+/**
  * Get the available image sizes
  * @since 3.0.0
  * @return array Returns a filtered array of image size strings
