Introduction
editMeziantou.Framework.Avatar generates avatars: small SVG or PNG images that show the initials of a name on a colored background. Use them for the users, teams or projects that have no picture.
What you can do with it
- Generate an avatar from a name, as an SVG string you embed in a page or save as a file. See Getting started.
- Change its appearance: the shape, the size and the palette of colors. See Appearance.
- Control the initials: the library picks one or two graphemes from the name, or uses the text you give. See Initials.
- Make it accessible: announce the full name, or hide a decorative avatar from screen readers. See Accessibility.
- Rely on stable colors: the same name always gets the same color, for a given palette. See Stable colors.
- Draw it as an image: create the avatar as a vector scene, and draw it as a PNG, WebP or JPEG image. See Image rendering.
Principles
- Deterministic. The output depends only on the name and the options: no randomness, no state.
- SVG first. CreateSvg returns an SVG string, drawn by the browser with its bold monospace font. CreateScene returns a vector scene to draw as an image with
Meziantou.Framework.Imaging.VectorGraphics. - Safe with untrusted names. The output is always well-formed XML, whatever the name contains.
Namespace
The types are in the Meziantou.Framework namespace:
| Type | Contains |
|---|---|
| AvatarGenerator | The CreateSvg and CreateScene methods |
| AvatarOptions | The shape, the size, the palette, the initials and the accessibility options |
| AvatarShape | Round, Square and RoundedSquare |
| AvatarColorPair | A background color and a foreground color |
Next steps
- Getting started: install the package and generate your first avatar.