Make WordPress Core

Ticket #17626: 17626.patch

File 17626.patch, 1.9 KB (added by SergeyBiryukov, 13 years ago)
  • wp-includes/media.php

     
    528528
    529529        // get the best one for a specified set of dimensions
    530530        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
    531534                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                        }
    532541                        // 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] ) ) {
    534543                                $file = $data['file'];
    535544                                list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
    536545                                return compact( 'file', 'width', 'height' );
     
    573582}
    574583
    575584/**
     585 * Callback to sort $imagemeta['sizes'] descending by width, height
     586 *
     587 * @since 3.1.0
     588 * @access private
     589 */
     590function _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/**
    576599 * Get the available image sizes
    577600 * @since 3.0.0
    578601 * @return array Returns a filtered array of image size strings