Changeset 30660 for trunk/src/wp-includes/media.php
- Timestamp:
- 11/30/2014 07:53:18 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r30656 r30660 380 380 $larger_ratio = max( $width_ratio, $height_ratio ); 381 381 382 if ( intval( $current_width * $larger_ratio ) > $max_width || intval( $current_height * $larger_ratio ) > $max_height )382 if ( (int) round( $current_width * $larger_ratio ) > $max_width || (int) round( $current_height * $larger_ratio ) > $max_height ) { 383 383 // The larger ratio is too big. It would result in an overflow. 384 384 $ratio = $smaller_ratio; 385 else385 } else { 386 386 // The larger ratio fits, and is likely to be a more "snug" fit. 387 387 $ratio = $larger_ratio; 388 } 388 389 389 390 // Very small dimensions may result in 0, 1 should be the minimum. 390 $w = max ( 1, intval( $current_width * $ratio ) );391 $h = max ( 1, intval( $current_height * $ratio ) );391 $w = max ( 1, (int) round( $current_width * $ratio ) ); 392 $h = max ( 1, (int) round( $current_height * $ratio ) ); 392 393 393 394 // Sometimes, due to rounding, we'll end up with a result like this: 465x700 in a 177x177 box is 117x176... a pixel short 394 395 // We also have issues with recursive calls resulting in an ever-changing result. Constraining to the result of a constraint should yield the original result. 395 396 // Thus we look for dimensions that are one pixel shy of the max value and bump them up 396 if ( $did_width && $w == $max_width - 1 ) 397 398 // Note: $did_width means it is possible $smaller_ratio == $width_ratio. 399 if ( $did_width && $w == $max_width - 1 ) { 397 400 $w = $max_width; // Round it up 398 if ( $did_height && $h == $max_height - 1 ) 401 } 402 403 // Note: $did_height means it is possible $smaller_ratio == $height_ratio. 404 if ( $did_height && $h == $max_height - 1 ) { 399 405 $h = $max_height; // Round it up 400 401 return array( $w, $h ); 406 } 407 408 return apply_filters( 'wp_constrain_dimensions', array( $w, $h ), $current_width, $current_height, $max_width, $max_height ); 402 409 } 403 410 … … 460 467 $new_h = min($dest_h, $orig_h); 461 468 462 if ( ! $new_w ) {463 $new_w = intval($new_h * $aspect_ratio);464 } 465 466 if ( ! $new_h ) {467 $new_h = intval($new_w / $aspect_ratio);469 if ( ! $new_w ) { 470 $new_w = (int) round( $new_h * $aspect_ratio ); 471 } 472 473 if ( ! $new_h ) { 474 $new_h = (int) round( $new_w / $aspect_ratio ); 468 475 } 469 476
Note: See TracChangeset
for help on using the changeset viewer.