Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ":")
Expand Down