Improved avatar downloader

This commit is contained in:
Eduard Urbach 2017-06-13 17:40:29 +02:00
parent 6836fea857
commit e2b87bddd4
3 changed files with 20 additions and 5 deletions

View File

@ -8,7 +8,6 @@ import (
"image/png" "image/png"
"io/ioutil" "io/ioutil"
"github.com/animenotifier/arn"
"github.com/nfnt/resize" "github.com/nfnt/resize"
) )
@ -39,7 +38,15 @@ func (output *AvatarOriginalFileOutput) SaveAvatar(avatar *Avatar) error {
img := avatar.Image img := avatar.Image
if img.Bounds().Dx() != output.Size { if img.Bounds().Dx() != output.Size {
img = resize.Resize(arn.AvatarSmallSize, 0, img, resize.Lanczos3) // 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)
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
var err error var err error

View File

@ -18,7 +18,15 @@ func (output *AvatarWebPFileOutput) SaveAvatar(avatar *Avatar) error {
// Resize if needed // Resize if needed
if img.Bounds().Dx() != output.Size { if img.Bounds().Dx() != output.Size {
img = resize.Resize(arn.AvatarSmallSize, 0, img, resize.Lanczos3) // 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)
} }
// Write to file // Write to file

View File

@ -31,10 +31,10 @@ func main() {
avatarSources = []AvatarSource{ avatarSources = []AvatarSource{
&Gravatar{ &Gravatar{
Rating: "pg", Rating: "pg",
RequestLimiter: time.NewTicker(250 * time.Millisecond), RequestLimiter: time.NewTicker(150 * time.Millisecond),
}, },
&MyAnimeList{ &MyAnimeList{
RequestLimiter: time.NewTicker(500 * time.Millisecond), RequestLimiter: time.NewTicker(150 * time.Millisecond),
}, },
} }