From cd922e500fe81ca6dd26efe04909e1f4bec9b0e0 Mon Sep 17 00:00:00 2001 From: fajrifernanda Date: Mon, 13 Jul 2020 10:31:36 +0700 Subject: [PATCH] bugfix: fix caclulating width height from aspectratio --- options.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/options.go b/options.go index c2927741..d41a83fc 100644 --- a/options.go +++ b/options.go @@ -87,14 +87,19 @@ func transformByAspectRatio(params map[string]interface{}) (width, height int) { } if width != 0 { - height = width / aspectRatio["width"] * aspectRatio["height"] + height = calculateFromAspectRatio(width, aspectRatio["height"], aspectRatio["width"]) } else { - width = height / aspectRatio["height"] * aspectRatio["width"] + width = calculateFromAspectRatio(height, aspectRatio["width"], aspectRatio["height"]) } return } +func calculateFromAspectRatio(x int, ratioA int, ratioB int) int { + res := float32(x) * (float32(ratioA) / float32(ratioB)) + return int(res) +} + func parseAspectRatio(val string) map[string]int { val = strings.TrimSpace(strings.ToLower(val)) slicedVal := strings.Split(val, ":")