Make WordPress Core

Changeset 12280


Ignore:
Timestamp:
11/26/2009 06:58:21 AM (17 years ago)
Author:
azaozz
Message:

Avoid a rare case of black line in cropped thumbnails, props miqrogroove, fixes #7748

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/media.php

    r12153 r12280  
    260260 * @return bool|array False, on failure. Returned array matches parameters for imagecopyresampled() PHP function.
    261261 */
    262 function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop=false) {
     262function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) {
    263263
    264264        if ($orig_w <= 0 || $orig_h <= 0)
     
    273273                $new_w = min($dest_w, $orig_w);
    274274                $new_h = min($dest_h, $orig_h);
    275                 if (!$new_w) {
     275
     276                if ( !$new_w ) {
    276277                        $new_w = intval($new_h * $aspect_ratio);
    277278                }
    278                 if (!$new_h) {
     279
     280                if ( !$new_h ) {
    279281                        $new_h = intval($new_w / $aspect_ratio);
    280282                }
     
    282284                $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
    283285
    284                 $crop_w = ceil($new_w / $size_ratio);
    285                 $crop_h = ceil($new_h / $size_ratio);
    286 
    287                 $s_x = floor(($orig_w - $crop_w)/2);
    288                 $s_y = floor(($orig_h - $crop_h)/2);
    289         }
    290         else {
     286                $crop_w = round($new_w / $size_ratio);
     287                $crop_h = round($new_h / $size_ratio);
     288
     289                $s_x = floor( ($orig_w - $crop_w) / 2 );
     290                $s_y = floor( ($orig_h - $crop_h) / 2 );
     291        } else {
    291292                // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
    292293                $crop_w = $orig_w;
     
    300301
    301302        // if the resulting image would be the same size or larger we don't want to resize it
    302         if ($new_w >= $orig_w && $new_h >= $orig_h)
     303        if ( $new_w >= $orig_w && $new_h >= $orig_h )
    303304                return false;
    304305
    305306        // the return array matches the parameters to imagecopyresampled()
    306307        // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
    307         return array(0, 0, $s_x, $s_y, $new_w, $new_h, $crop_w, $crop_h);
     308        return array( 0, 0, $s_x, $s_y, $new_w, $new_h, $crop_w, $crop_h );
    308309
    309310}
Note: See TracChangeset for help on using the changeset viewer.