From 9b6989c3ce6c28a5be31f4850d78abfa3c3bf1af Mon Sep 17 00:00:00 2001 From: Dan Persa Date: Fri, 13 Jan 2017 16:13:51 +0100 Subject: [PATCH] Fix: Crop is doing resize. Closes #128 --- image_test.go | 4 ++-- resize.go | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/image_test.go b/image_test.go index 7f805b0..dce17ba 100644 --- a/image_test.go +++ b/image_test.go @@ -176,7 +176,7 @@ func TestImageCropByWidth(t *testing.T) { t.Errorf("Cannot process the image: %s", err) } - err = assertSize(buf, 600, 375) + err = assertSize(buf, 600, 1050) if err != nil { t.Error(err) } @@ -190,7 +190,7 @@ func TestImageCropByHeight(t *testing.T) { t.Errorf("Cannot process the image: %s", err) } - err = assertSize(buf, 480, 300) + err = assertSize(buf, 1680, 300) if err != nil { t.Error(err) } diff --git a/resize.go b/resize.go index 8b5b8df..bab21f1 100644 --- a/resize.go +++ b/resize.go @@ -401,12 +401,20 @@ func imageCalculations(o *Options, inWidth, inHeight int) float64 { } // Fixed width, auto height case o.Width > 0: - factor = xfactor - o.Height = roundFloat(float64(inHeight) / factor) + if o.Crop { + o.Height = inHeight + } else { + factor = xfactor + o.Height = roundFloat(float64(inHeight) / factor) + } // Fixed height, auto width case o.Height > 0: - factor = yfactor - o.Width = roundFloat(float64(inWidth) / factor) + if o.Crop { + o.Width = inWidth + } else { + factor = yfactor + o.Width = roundFloat(float64(inWidth) / factor) + } // Identity transform default: o.Width = inWidth