Make font size depend on avatar size

This commit is contained in:
kolaente 2020-08-01 19:55:02 +02:00
parent 6aa69372a2
commit e7439eaae1
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 6 additions and 4 deletions

View File

@ -49,13 +49,15 @@ var (
)
const (
fontSize = 900
dpi = 72
defaultSize = 1024
)
func drawImage(text rune, bg *color.RGBA) (img *image.RGBA64, err error) {
size := defaultSize
fontSize := float64(size) * 0.9
// Inspired by https://github.com/holys/initials-avatar
// Get the font
@ -65,7 +67,7 @@ func drawImage(text rune, bg *color.RGBA) (img *image.RGBA64, err error) {
}
// Build the image background
img = image.NewRGBA64(image.Rect(0, 0, defaultSize, defaultSize))
img = image.NewRGBA64(image.Rect(0, 0, size, size))
draw.Draw(img, img.Bounds(), &image.Uniform{C: bg}, image.Point{}, draw.Src)
// Add the text
@ -92,8 +94,8 @@ func drawImage(text rune, bg *color.RGBA) (img *image.RGBA64, err error) {
}
// Center
dY := (defaultSize - int(gbuf.Bounds.Max.Y-gbuf.Bounds.Min.Y)>>6) / 2
dX := (defaultSize - int(gbuf.Bounds.Max.X-gbuf.Bounds.Min.X)>>6) / 2
dY := (size - int(gbuf.Bounds.Max.Y-gbuf.Bounds.Min.Y)>>6) / 2
dX := (size - int(gbuf.Bounds.Max.X-gbuf.Bounds.Min.X)>>6) / 2
y := int(gbuf.Bounds.Max.Y>>6) + dY
x := 0 - int(gbuf.Bounds.Min.X>>6) + dX