1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-09-16 09:36:18 +02:00

Round sizes for more accurate calculations

This commit is contained in:
DarthSim
2019-06-08 00:24:48 +06:00
parent dbad387eef
commit b2c5e9c4ab
2 changed files with 12 additions and 6 deletions

View File

@@ -191,8 +191,8 @@ func transformImage(ctx context.Context, img *vipsImage, data []byte, po *proces
scale := calcScale(widthToScale, heightToScale, po, imgtype)
cropWidth = int(float64(cropWidth) * scale)
cropHeight = int(float64(cropHeight) * scale)
cropWidth = roundToInt(float64(cropWidth) * scale)
cropHeight = roundToInt(float64(cropHeight) * scale)
if scale != 1 && data != nil && canScaleOnLoad(imgtype, scale) {
if imgtype == imageTypeWEBP || imgtype == imageTypeSVG {
@@ -212,8 +212,8 @@ func transformImage(ctx context.Context, img *vipsImage, data []byte, po *proces
// Update scale after scale-on-load
newWidth, newHeight, _, _ := extractMeta(img)
widthToScale = int(float64(widthToScale) * float64(newWidth) / float64(srcWidth))
heightToScale = int(float64(heightToScale) * float64(newHeight) / float64(srcHeight))
widthToScale = roundToInt(float64(widthToScale) * float64(newWidth) / float64(srcWidth))
heightToScale = roundToInt(float64(heightToScale) * float64(newHeight) / float64(srcHeight))
scale = calcScale(widthToScale, heightToScale, po, imgtype)
}
@@ -264,8 +264,8 @@ func transformImage(ctx context.Context, img *vipsImage, data []byte, po *proces
checkTimeout(ctx)
dprWidth := int(float64(po.Width) * po.Dpr)
dprHeight := int(float64(po.Height) * po.Dpr)
dprWidth := roundToInt(float64(po.Width) * po.Dpr)
dprHeight := roundToInt(float64(po.Height) * po.Dpr)
cropGravity := po.Crop.Gravity
if cropGravity.Type == gravityUnknown {

View File

@@ -1,5 +1,7 @@
package main
import "math"
func maxInt(a, b int) int {
if a > b {
return a
@@ -13,3 +15,7 @@ func minInt(a, b int) int {
}
return b
}
func roundToInt(a float64) int {
return int(math.Round(a))
}