mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-08 23:18:19 -07:00
Auto-width and height calculations now round instead of floor.
This commit is contained in:
parent
1278491e23
commit
552db7d3b5
2 changed files with 31 additions and 2 deletions
12
resize.go
12
resize.go
|
|
@ -403,11 +403,11 @@ func imageCalculations(o *Options, inWidth, inHeight int) float64 {
|
|||
// Fixed width, auto height
|
||||
case o.Width > 0:
|
||||
factor = xfactor
|
||||
o.Height = int(math.Floor(float64(inHeight) / factor))
|
||||
o.Height = roundFloat(float64(inHeight) / factor)
|
||||
// Fixed height, auto width
|
||||
case o.Height > 0:
|
||||
factor = yfactor
|
||||
o.Width = int(math.Floor(float64(inWidth) / factor))
|
||||
o.Width = roundFloat(float64(inWidth) / factor)
|
||||
// Identity transform
|
||||
default:
|
||||
o.Width = inWidth
|
||||
|
|
@ -418,6 +418,14 @@ func imageCalculations(o *Options, inWidth, inHeight int) float64 {
|
|||
return factor
|
||||
}
|
||||
|
||||
func roundFloat(f float64) int {
|
||||
if f < 0 {
|
||||
return int(math.Ceil(f - 0.5))
|
||||
} else {
|
||||
return int(math.Floor(f + 0.5))
|
||||
}
|
||||
}
|
||||
|
||||
func calculateCrop(inWidth, inHeight, outWidth, outHeight int, gravity Gravity) (int, int) {
|
||||
left, top := 0, 0
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue