Improved avatar downloader

This commit is contained in:
Eduard Urbach 2017-06-14 18:15:08 +02:00
parent 0ee267a692
commit c0ffa522b9
2 changed files with 4 additions and 20 deletions

View File

@ -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

View File

@ -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