Make WordPress Core

Ticket #22738: 22738.diff

File 22738.diff, 1.6 KB (added by jond3r, 11 years ago)
  • wp-includes/media.php

     
    252252 * @return array First item is the width, the second item is the height.
    253253 */
    254254function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, $max_height=0 ) {
    255         if ( !$max_width and !$max_height )
     255        if ( ( !$max_width and !$max_height ) || ( $max_width == $current_width && $max_height == $current_height ) )
    256256                return array( $current_width, $current_height );
    257257
    258258        $width_ratio = $height_ratio = 1.0;
     
    13691369
    13701370                                // Nothing from the filter, so consult image metadata if we have it.
    13711371                                $size_meta = $meta['sizes'][ $size ];
     1372
     1373                                // We have the actual image size, but might need to further constrain it if content_width is narrower
     1374                                // This is not necessary for thumbnails and medium size
     1375                                if ( 'thumbnail' == $size || 'medium' == $size ) {
     1376                                        $width = $size_meta['width'];
     1377                                        $height = $size_meta['height'];
     1378                                }
     1379                                else
     1380                                        list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size );
     1381
    13721382                                $sizes[ $size ] = array(
    1373                                         'height'      => $size_meta['height'],
    1374                                         'width'       => $size_meta['width'],
     1383                                        'height'      => $height,
     1384                                        'width'       => $width,
    13751385                                        'url'         => $base_url . $size_meta['file'],
    1376                                         'orientation' => $size_meta['height'] > $size_meta['width'] ? 'portrait' : 'landscape',
     1386                                        'orientation' => $height > $width ? 'portrait' : 'landscape',
    13771387                                );
    13781388                        }
    13791389                }