From 12cb3a353efdee4892082ea642d5e73f49b466a8 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Wed, 9 Oct 2013 19:06:56 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@25744 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/image-edit.php | 4 ++-- src/wp-includes/media.php | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/image-edit.php b/src/wp-admin/includes/image-edit.php index 9d717d7ea4..72e9037d1d 100644 --- a/src/wp-admin/includes/image-edit.php +++ b/src/wp-admin/includes/image-edit.php @@ -467,8 +467,8 @@ function stream_preview_image( $post_id ) { $h = $size['height']; $ratio = _image_get_preview_ratio( $w, $h ); - $w2 = $w * $ratio; - $h2 = $h * $ratio; + $w2 = max ( 1, $w * $ratio ); + $h2 = max ( 1, $h * $ratio ); if ( is_wp_error( $img->resize( $w2, $h2 ) ) ) return false; diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 5598a5a3f5..8e150a597c 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -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.