WordPress.org

Make WordPress Core

Ticket #18799: 18799.diff

File 18799.diff, 900 bytes (added by solarissmoke, 3 years ago)

Check original image first before attempting to find a smaller one

  • wp-includes/media.php

     
    526526        if ( !is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) ) 
    527527                return false; 
    528528 
     529        // check the original image first! 
     530        if ( is_array( $size ) && ( ( $imagedata['width'] == $size[0] && $imagedata['height'] <= $size[1] ) || ( $imagedata['height'] == $size[1] && $imagedata['width'] <= $size[0] ) ) ) { 
     531                $file = basename( $imagedata['file'] ); 
     532                list($width, $height) = image_constrain_size_for_editor( $imagedata['width'], $imagedata['height'], $size ); 
     533                return compact( 'file', 'width', 'height' ); 
     534        } 
     535         
    529536        // get the best one for a specified set of dimensions 
    530537        if ( is_array($size) && !empty($imagedata['sizes']) ) { 
    531538                foreach ( $imagedata['sizes'] as $_size => $data ) {