Skip to content

Commit

Permalink
fix: add Arabic font support and SVG upload
Browse files Browse the repository at this point in the history
  • Loading branch information
BasselArt committed Dec 29, 2024
1 parent 2c1226f commit 31108ef
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions app/handlers/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,24 @@ func Gravatar() web.HandlerFunc {
name = "?"
}

// Call LetterAvatar handler directly with the name
return LetterAvatar()(web.NewContext(c.Request, c.Response, c.Engine(), web.Map{
"id": fmt.Sprint(id),
"name": name,
}))
// Extract and draw letter avatar
extractedLetter := letteravatar.Extract(name)
img, err := letteravatar.Draw(size, extractedLetter, &letteravatar.Options{
PaletteKey: fmt.Sprintf("%d:%s", id, name),
})
if err != nil {
log.Error(c, err)
return c.Failure(err)
}

buf := new(bytes.Buffer)
err = png.Encode(buf, img)
if err != nil {
log.Error(c, err)
return c.Failure(err)
}

return c.Image("image/png", buf.Bytes())
}
}

Expand Down

0 comments on commit 31108ef

Please sign in to comment.