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, ":")