2022-08-11 15:26:55 +00:00
|
|
|
package profilepictures
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
"image/draw"
|
|
|
|
|
|
|
|
"github.com/fogleman/gg"
|
|
|
|
"golang.org/x/image/font"
|
|
|
|
"golang.org/x/image/math/fixed"
|
|
|
|
)
|
|
|
|
|
|
|
|
func DefaultProfilePicture(initials string) *image.RGBA {
|
|
|
|
img := image.NewRGBA(image.Rect(0, 0, 300, 300))
|
|
|
|
col := color.RGBA{36, 56, 135, 255}
|
|
|
|
white := color.RGBA{255, 255, 255, 255}
|
|
|
|
point := fixed.Point26_6{fixed.I(40), fixed.I(200)}
|
|
|
|
|
|
|
|
draw.Draw(img, img.Bounds(), &image.Uniform{col}, image.Point{X: 0, Y: 0}, draw.Src)
|
|
|
|
|
2022-10-17 03:02:19 +00:00
|
|
|
ff, err := gg.LoadFontFace("themes/default/web/fonts/bitter.ttf", 150.0)
|
2022-08-11 15:26:55 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return img
|
|
|
|
}
|
|
|
|
|
|
|
|
d := &font.Drawer{
|
|
|
|
Dst: img,
|
|
|
|
Src: image.NewUniform(white),
|
|
|
|
Face: ff,
|
|
|
|
Dot: point,
|
|
|
|
}
|
|
|
|
d.DrawString(initials)
|
|
|
|
|
|
|
|
return img
|
|
|
|
}
|