Changeset 46077 for trunk/src/wp-includes/media.php
- Timestamp:
- 09/07/2019 01:33:16 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/media.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r46066 r46077 544 544 } 545 545 546 // Stop if the destination size is larger than the original image dimensions. 547 if ( empty( $dest_h ) ) { 548 if ( $orig_w < $dest_w ) { 549 return false; 550 } 551 } elseif ( empty( $dest_w ) ) { 552 if ( $orig_h < $dest_h ) { 553 return false; 554 } 555 } else { 556 if ( $orig_w < $dest_w && $orig_h < $dest_h ) { 557 return false; 558 } 559 } 560 546 561 if ( $crop ) { 547 // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h 562 // Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h. 563 // Note that the requested crop dimensions are used as a maximum bounding box for the original image. 564 // If the original image's width or height is less than the requested width or height 565 // only the greater one will be cropped. 566 // For example when the original image is 600x300, and the requested crop dimensions are 400x400, 567 // the resulting image will be 400x300. 548 568 $aspect_ratio = $orig_w / $orig_h; 549 569 $new_w = min( $dest_w, $orig_w ); … … 585 605 } 586 606 } else { 587 // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box607 // Resize using $dest_w x $dest_h as a maximum bounding box. 588 608 $crop_w = $orig_w; 589 609 $crop_h = $orig_h; … … 595 615 } 596 616 597 // if the resulting image would be the same size or larger we don't want to resize it 598 if ( $new_w >= $orig_w && $new_h >= $orig_h && intval( $dest_w ) !== intval( $orig_w ) && intval( $dest_h ) !== intval( $orig_h ) ) { 599 return false; 600 } 601 602 // the return array matches the parameters to imagecopyresampled() 617 if ( wp_fuzzy_number_match( $new_w, $orig_w ) && wp_fuzzy_number_match( $new_h, $orig_h ) ) { 618 // The new size has virtually the same dimensions as the original image. 619 620 /** 621 * Filters whether to proceed with making an image sub-size with identical dimensions 622 * with the original/source image. Differences of 1px may be due to rounding and are ignored. 623 * 624 * @since 5.3.0 625 * 626 * @param bool The filtered value. 627 * @param int Original image width. 628 * @param int Original image height. 629 */ 630 $proceed = (bool) apply_filters( 'wp_image_resize_identical_dimensions', false, $orig_w, $orig_h ); 631 632 if ( ! $proceed ) { 633 return false; 634 } 635 } 636 637 // The return array matches the parameters to imagecopyresampled(). 603 638 // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h 604 639 return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h ); 605 606 640 } 607 641 … … 665 699 666 700 // If the image dimensions are within 1px of the expected size, we consider it a match. 667 $matched = ( abs( $constrained_size[0] - $expected_size[0] ) <= 1 && abs( $constrained_size[1] - $expected_size[1] ) <= 1);701 $matched = ( wp_fuzzy_number_match( $constrained_size[0], $expected_size[0] ) && wp_fuzzy_number_match( $constrained_size[1], $expected_size[1] ) ); 668 702 669 703 return $matched;
Note: See TracChangeset
for help on using the changeset viewer.