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
img := avatar.Image
if img.Bounds().Dx() != output.Size {
// Use Lanczos interpolation for downscales
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)
if img.Bounds().Dx() > output.Size {
img = resize.Resize(uint(output.Size), 0, img, resize.Lanczos3)
buffer := new(bytes.Buffer)
var err error

View File

@ -17,16 +17,8 @@ func (output *AvatarWebPFileOutput) SaveAvatar(avatar *Avatar) error {
img := avatar.Image
// Resize if needed
if img.Bounds().Dx() != output.Size {
// Use Lanczos interpolation for downscales
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)
if img.Bounds().Dx() > output.Size {
img = resize.Resize(arn.AvatarSmallSize, 0, img, resize.Lanczos3)
}
// Write to file