reprogl
1package avatar2
3import (4"errors"5"image"6"image/draw"7"strconv"8
9xdraw "golang.org/x/image/draw"10)
11
12func tryUserSource(id, size int) (image.Image, error) {13extensions := []string{".png", ".jpg"}14for _, ext := range extensions {15filename := "public/data/pictures/user." + strconv.Itoa(id) + ext16img, err := loadImage(filename)17if err != nil {18continue19}20
21imageResult := image.NewRGBA(image.Rect(0, 0, size, size))22xdraw.BiLinear.Scale(imageResult, imageResult.Bounds(), img, img.Bounds(), draw.Src, nil)23
24return imageResult, nil25}26
27return nil, errors.New("avatar: not found on public/data/pictures")28}
29