Make WordPress Core

Ticket #18532: 18532.2.patch

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

     
    294294        $smaller_ratio = min( $width_ratio, $height_ratio );
    295295        $larger_ratio  = max( $width_ratio, $height_ratio );
    296296
    297         if ( intval( $current_width * $larger_ratio ) > $max_width || intval( $current_height * $larger_ratio ) > $max_height )
     297        if ( round( $current_width * $larger_ratio ) > $max_width || round( $current_height * $larger_ratio ) > $max_height )
    298298                // The larger ratio is too big. It would result in an overflow.
    299299                $ratio = $smaller_ratio;
    300300        else
    301301                // The larger ratio fits, and is likely to be a more "snug" fit.
    302302                $ratio = $larger_ratio;
    303303
    304         $w = intval( $current_width  * $ratio );
    305         $h = intval( $current_height * $ratio );
     304        $w = round( $current_width  * $ratio );
     305        $h = round( $current_height * $ratio );
    306306
    307307        // Sometimes, due to rounding, we'll end up with a result like this: 465x700 in a 177x177 box is 117x176... a pixel short
    308308        // We also have issues with recursive calls resulting in an ever-changing result. Contraining to the result of a constraint should yield the original result.
     
    312312        if ( $did_height && $h == $max_height - 1 )
    313313                $h = $max_height; // Round it up
    314314
    315         return array( $w, $h );
     315        return apply_filters( 'wp_constrain_dimensions', array( $w, $h ), $current_width, $current_height, $max_width, $max_height );
    316316}
    317317
    318318/**