Make sure when resizing an image according to ratio we do not end up with a zero-pixel width or height.

props plocha.
fixes #25038.

Built from https://develop.svn.wordpress.org/trunk@25744


git-svn-id: http://core.svn.wordpress.org/trunk@25657 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin
2013-10-09 19:07:17 +00:00
parent 66be5edfb5
commit f0eb99952c
2 changed files with 5 additions and 4 deletions

View File

@@ -284,8 +284,9 @@ function wp_constrain_dimensions( $current_width, $current_height, $max_width=0,
// The larger ratio fits, and is likely to be a more "snug" fit.
$ratio = $larger_ratio;
$w = intval( $current_width * $ratio );
$h = intval( $current_height * $ratio );
// Very small dimensions may result in 0, 1 should be the minimum.
$w = max ( 1, intval( $current_width * $ratio ) );
$h = max ( 1, intval( $current_height * $ratio ) );
// Sometimes, due to rounding, we'll end up with a result like this: 465x700 in a 177x177 box is 117x176... a pixel short
// 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.