mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Fix image resizing calculation to use square root for scaling factor
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"github.com/disintegration/imaging"
|
"github.com/disintegration/imaging"
|
||||||
"image"
|
"image"
|
||||||
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"nysoure/server/dao"
|
"nysoure/server/dao"
|
||||||
"nysoure/server/model"
|
"nysoure/server/model"
|
||||||
@@ -232,7 +233,7 @@ func getOrCreateResampledImage(i model.Image) ([]byte, error) {
|
|||||||
return imgData, nil // No need to resample if the image is small enough
|
return imgData, nil // No need to resample if the image is small enough
|
||||||
}
|
}
|
||||||
|
|
||||||
scale := float64(resampledMaxPixels) / float64(pixels)
|
scale := math.Sqrt(float64(resampledMaxPixels) / float64(pixels))
|
||||||
dstWidth := int(float64(img.Bounds().Dx()) * scale)
|
dstWidth := int(float64(img.Bounds().Dx()) * scale)
|
||||||
dstHeight := int(float64(img.Bounds().Dy()) * scale)
|
dstHeight := int(float64(img.Bounds().Dy()) * scale)
|
||||||
dstImg := imaging.Resize(img, dstWidth, dstHeight, imaging.Lanczos)
|
dstImg := imaging.Resize(img, dstWidth, dstHeight, imaging.Lanczos)
|
||||||
|
Reference in New Issue
Block a user