quintodrome/utils/gravatar/gravatar.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
430 B
Go
Raw Normal View History

package gravatar
import (
2024-07-23 13:49:46 -08:00
"crypto/sha256"
"fmt"
"strings"
)
const baseUrl = "https://www.gravatar.com/avatar"
const defaultSize = 80
const maxSize = 2048
func Url(email string, size int) string {
email = strings.ToLower(email)
email = strings.TrimSpace(email)
2024-07-23 13:49:46 -08:00
hash := sha256.Sum256([]byte(email))
if size < 1 {
size = defaultSize
}
2024-02-16 17:48:25 -09:00
size = min(maxSize, size)
return fmt.Sprintf("%s/%x?s=%d", baseUrl, hash, size)
}