Ticket #17626: 17626.patch
File 17626.patch, 1.9 KB (added by , 13 years ago) |
---|
-
wp-includes/media.php
528 528 529 529 // get the best one for a specified set of dimensions 530 530 if ( is_array($size) && !empty($imagedata['sizes']) ) { 531 // sort $imagemeta['sizes'] descending by width, height 532 uasort( $imagedata['sizes'], '_compare_imagedata_sizes' ); 533 // loop through $imagemeta['sizes'] to find the right thumbnail size 531 534 foreach ( $imagedata['sizes'] as $_size => $data ) { 535 // already cropped exactly to width and height; so use this size 536 if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) { 537 $file = $data['file']; 538 list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size ); 539 return compact( 'file', 'width', 'height' ); 540 } 532 541 // already cropped to width or height; so use this size 533 if ( ( $data['width'] == $size[0] && $data['height'] <= $size[1] ) || ( $data['height'] == $size[1] && $data['width'] <= $size[0] ) ) {542 elseif ( ( $data['width'] == $size[0] && $data['height'] <= $size[1] ) || ( $data['height'] == $size[1] && $data['width'] <= $size[0] ) ) { 534 543 $file = $data['file']; 535 544 list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size ); 536 545 return compact( 'file', 'width', 'height' ); … … 573 582 } 574 583 575 584 /** 585 * Callback to sort $imagemeta['sizes'] descending by width, height 586 * 587 * @since 3.1.0 588 * @access private 589 */ 590 function _compare_imagedata_sizes( $a, $b ) { 591 $sorted = strnatcmp( $a['width'], $b['width'] ); 592 if ( ! $sorted ) 593 return strnatcmp( $a['height'], $b['height'] ); 594 array_reverse( $sorted ); 595 return $sorted; 596 } 597 598 /** 576 599 * Get the available image sizes 577 600 * @since 3.0.0 578 601 * @return array Returns a filtered array of image size strings