28 lines
622 B
Go
Raw Normal View History

2017-06-13 12:47:17 +00:00
package main
import (
"github.com/animenotifier/arn"
"github.com/nfnt/resize"
)
// AvatarWebPFileOutput ...
type AvatarWebPFileOutput struct {
Directory string
Size int
Quality float32
}
// SaveAvatar writes the avatar in WebP format to the file system.
func (output *AvatarWebPFileOutput) SaveAvatar(avatar *Avatar) error {
img := avatar.Image
// Resize if needed
2017-06-14 16:15:08 +00:00
if img.Bounds().Dx() > output.Size {
img = resize.Resize(arn.AvatarSmallSize, 0, img, resize.Lanczos3)
2017-06-13 12:47:17 +00:00
}
// Write to file
fileName := output.Directory + avatar.User.ID + ".webp"
return arn.SaveWebP(img, fileName, output.Quality)
}