github.com/spi-ca/misc@v1.0.1/nums/geometry.go (about) 1 package nums 2 3 import "image" 4 5 // AspectRatio returns geometry that conforms to the aspect ratio. 6 func AspectRatio(srcRect image.Point, toResize uint64) image.Point { 7 w, h := int(toResize), getRatioSize(int(toResize), srcRect.Y, srcRect.X) 8 if srcRect.X < srcRect.Y { 9 w, h = getRatioSize(int(toResize), srcRect.X, srcRect.Y), int(toResize) 10 } 11 return image.Point{w, h} 12 } 13 14 func getRatioSize(a, b, c int) int { 15 d := a * b / c 16 return (d + 1) & -1 17 }