The avatar component helps you generate a default user avatar using its credentials.


Example

public ActionResult GetAvatar(string name)
{
    var avatarStream = new BsAvatarBuilder()
        //.Circle()
        .FontColor(Color.White)
        .Name(name)
        .ToStream();

    return this.File(avatarStream.GetBuffer(), "image/png");
}

Configuration

BsAvatarBuilder

Methods

Size(int size) | Size(int width, int height)

params:

  • size

    type int
    default 64
    description Size of avatar in pixels.

Sets the avatar dimensions (width/height)


BackgroundColor(string hex) | BackgroundColor(Color color)

params:

  • hex

    type string
    default random
    description Hex color code.

  • color

    type struct Color
    default random

Sets the background color


FontColor(string hex) | FontColor(Color color)

params:

  • hex

    type string
    default random monochrome color
    description Hex color code.

  • color

    type struct Color
    default random monochrome color

Sets the font color


Font(string fontFamily, float fontSize, FontStyle fontStyle) | Font(Font font)

params:

  • fontFamily

    type string
    default "Arial"
    description Font family

  • fontSize

    type float
    default 20
    description Font size

  • fontStyle

    type enum FontStyle
    default FontStyle.Bold
    description Font style

  • font

    type struct Font
    default Arial 20 Bold

Sets the font family, size and style


Text(string text)

params:

  • text

    type string
    default null
    description Avatar text.

Sets the drawn text


Name(string fullName)

params:

  • fullName

    type string
    default null
    description Full user name (eg "Mike Johnson").

Sets the drawn text as the credentials of the user name


Circle()

Rounded corners


MemoryStream ToStream()

Generates a stream using the specified configuration


byte[] ToByteArray()

Generates a byte array representation of the configured avatar