From 3d186505cf9bfd892269f5e384d3f9a945f89cdc Mon Sep 17 00:00:00 2001 From: Kirill Date: Wed, 20 Feb 2019 11:02:53 +0400 Subject: [PATCH 1/2] Replace Round function with Ceil in fit method There is a problem when fitWidth = 100.234. Round method make fitWidth equals to 100, but it should be 101 (to prevent black line appearing) --- image.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/image.go b/image.go index 0466a0f0..4652c485 100644 --- a/image.go +++ b/image.go @@ -154,10 +154,10 @@ func Fit(buf []byte, o ImageOptions) (Image, error) { func calculateDestinationFitDimension(imageWidth, imageHeight, fitWidth, fitHeight int) (int, int) { if imageWidth*fitHeight > fitWidth*imageHeight { // constrained by width - fitHeight = int(math.Round(float64(fitWidth) * float64(imageHeight) / float64(imageWidth))) + fitHeight = int(math.Ceil(float64(fitWidth) * float64(imageHeight) / float64(imageWidth))) } else { // constrained by height - fitWidth = int(math.Round(float64(fitHeight) * float64(imageWidth) / float64(imageHeight))) + fitWidth = int(math.Ceil(float64(fitHeight) * float64(imageWidth) / float64(imageHeight))) } return fitWidth, fitHeight From 4c12bcae7277d25ab8014c5fada4d5baae1ef487 Mon Sep 17 00:00:00 2001 From: Kirill Date: Wed, 20 Feb 2019 16:19:33 +0400 Subject: [PATCH 2/2] Change fitWidth Round function to Ceil to prevent horizontal black line appear --- image.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image.go b/image.go index 4652c485..8e6f8cd5 100644 --- a/image.go +++ b/image.go @@ -154,7 +154,7 @@ func Fit(buf []byte, o ImageOptions) (Image, error) { func calculateDestinationFitDimension(imageWidth, imageHeight, fitWidth, fitHeight int) (int, int) { if imageWidth*fitHeight > fitWidth*imageHeight { // constrained by width - fitHeight = int(math.Ceil(float64(fitWidth) * float64(imageHeight) / float64(imageWidth))) + fitHeight = int(math.Round(float64(fitWidth) * float64(imageHeight) / float64(imageWidth))) } else { // constrained by height fitWidth = int(math.Ceil(float64(fitHeight) * float64(imageWidth) / float64(imageHeight)))