Improved avatar downloader
This commit is contained in:
parent
0ee267a692
commit
c0ffa522b9
@ -37,16 +37,8 @@ func (output *AvatarOriginalFileOutput) SaveAvatar(avatar *Avatar) error {
|
|||||||
data := avatar.Data
|
data := avatar.Data
|
||||||
img := avatar.Image
|
img := avatar.Image
|
||||||
|
|
||||||
if img.Bounds().Dx() != output.Size {
|
if img.Bounds().Dx() > output.Size {
|
||||||
// Use Lanczos interpolation for downscales
|
img = resize.Resize(uint(output.Size), 0, img, resize.Lanczos3)
|
||||||
interpolation := resize.Lanczos3
|
|
||||||
|
|
||||||
// Use Mitchell interpolation for upscales
|
|
||||||
if output.Size > img.Bounds().Dx() {
|
|
||||||
interpolation = resize.MitchellNetravali
|
|
||||||
}
|
|
||||||
|
|
||||||
img = resize.Resize(uint(output.Size), 0, img, interpolation)
|
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
@ -17,16 +17,8 @@ func (output *AvatarWebPFileOutput) SaveAvatar(avatar *Avatar) error {
|
|||||||
img := avatar.Image
|
img := avatar.Image
|
||||||
|
|
||||||
// Resize if needed
|
// Resize if needed
|
||||||
if img.Bounds().Dx() != output.Size {
|
if img.Bounds().Dx() > output.Size {
|
||||||
// Use Lanczos interpolation for downscales
|
img = resize.Resize(arn.AvatarSmallSize, 0, img, resize.Lanczos3)
|
||||||
interpolation := resize.Lanczos3
|
|
||||||
|
|
||||||
// Use Mitchell interpolation for upscales
|
|
||||||
if output.Size > img.Bounds().Dx() {
|
|
||||||
interpolation = resize.MitchellNetravali
|
|
||||||
}
|
|
||||||
|
|
||||||
img = resize.Resize(arn.AvatarSmallSize, 0, img, interpolation)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to file
|
// Write to file
|
||||||
|
Loading…
Reference in New Issue
Block a user