From e6c3877455eb879973ef3897b469082ed9fd0792 Mon Sep 17 00:00:00 2001 From: Maciej Gryniuk Date: Sun, 10 May 2015 15:55:32 +0200 Subject: [PATCH 1/2] Fixed upscale if both width and height are lesser than destination. --- lib/ManualImageCrop.php | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/ManualImageCrop.php b/lib/ManualImageCrop.php index d0ac14d..0b47c25 100644 --- a/lib/ManualImageCrop.php +++ b/lib/ManualImageCrop.php @@ -207,22 +207,14 @@ public function cropImage() { $src_w = max(0, $_POST['select']['w']) * $_POST['previewScale']; $src_h = max(0, $_POST['select']['h']) * $_POST['previewScale']; - $size = wp_get_image_editor( $src_file )->get_size(); - - $is_higher = ( $dst_h > $size["height"] ); - $is_wider = ( $dst_w > $size["width"] ); - - if ( $is_higher || $is_wider ) : - if ( $is_higher ) - $scale = $src_h / $size["height"]; - else - $scale = $src_w / $size["width"]; - - $src_w = $src_w / $scale; - $src_h = $src_h / $scale; - $src_x = $src_x / $scale; - $src_y = $src_y / $scale; - endif; + if ( $dst_w > $size["width"] || $dst_h > $size["height"] ) { + $size_ratio = max($dst_w / $size["width"], $dst_h / $size["height"]); + + $src_w = round($dst_w / $size_ratio); + $src_h = round($dst_h / $size_ratio); + $src_x = round($src_x / $size_ratio); + $src_y = round($src_y / $size_ratio); + } //saves the selected area $imageMetadata = wp_get_attachment_metadata($_POST['attachmentId']); From cfbe976376c6b207c50b73b6f74f8d7a495d3fc8 Mon Sep 17 00:00:00 2001 From: Maciej Gryniuk Date: Sun, 10 May 2015 16:01:28 +0200 Subject: [PATCH 2/2] Missed $size... --- lib/ManualImageCrop.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ManualImageCrop.php b/lib/ManualImageCrop.php index 0b47c25..49ed20f 100644 --- a/lib/ManualImageCrop.php +++ b/lib/ManualImageCrop.php @@ -207,6 +207,8 @@ public function cropImage() { $src_w = max(0, $_POST['select']['w']) * $_POST['previewScale']; $src_h = max(0, $_POST['select']['h']) * $_POST['previewScale']; + $size = wp_get_image_editor( $src_file )->get_size(); + if ( $dst_w > $size["width"] || $dst_h > $size["height"] ) { $size_ratio = max($dst_w / $size["width"], $dst_h / $size["height"]);