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

git-svn-id: http://svn.automattic.com/wordpress/trunk@12280 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-11-26 06:58:21 +00:00
parent 5f74404560
commit 16ebe3bc82
1 changed files with 12 additions and 11 deletions

View File

@ -259,7 +259,7 @@ function wp_constrain_dimensions( $current_width, $current_height, $max_width=0,
* @param bool $crop Optional, default is false. Whether to crop image or resize.
* @return bool|array False, on failure. Returned array matches parameters for imagecopyresampled() PHP function.
*/
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop=false) {
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) {
if ($orig_w <= 0 || $orig_h <= 0)
return false;
@ -272,22 +272,23 @@ function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop=false
$aspect_ratio = $orig_w / $orig_h;
$new_w = min($dest_w, $orig_w);
$new_h = min($dest_h, $orig_h);
if (!$new_w) {
if ( !$new_w ) {
$new_w = intval($new_h * $aspect_ratio);
}
if (!$new_h) {
if ( !$new_h ) {
$new_h = intval($new_w / $aspect_ratio);
}
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
$crop_w = ceil($new_w / $size_ratio);
$crop_h = ceil($new_h / $size_ratio);
$crop_w = round($new_w / $size_ratio);
$crop_h = round($new_h / $size_ratio);
$s_x = floor(($orig_w - $crop_w)/2);
$s_y = floor(($orig_h - $crop_h)/2);
}
else {
$s_x = floor( ($orig_w - $crop_w) / 2 );
$s_y = floor( ($orig_h - $crop_h) / 2 );
} else {
// don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
$crop_w = $orig_w;
$crop_h = $orig_h;
@ -299,12 +300,12 @@ function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop=false
}
// if the resulting image would be the same size or larger we don't want to resize it
if ($new_w >= $orig_w && $new_h >= $orig_h)
if ( $new_w >= $orig_w && $new_h >= $orig_h )
return false;
// the return array matches the parameters to imagecopyresampled()
// int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
return array(0, 0, $s_x, $s_y, $new_w, $new_h, $crop_w, $crop_h);
return array( 0, 0, $s_x, $s_y, $new_w, $new_h, $crop_w, $crop_h );
}