Lueur Avatar - v0.1.8
    Preparing search index...

    Function generateAvatarSvg

    • Generates an SVG avatar based on the provided username and customization options.

      Parameters

      • username: string

        The name or identifier used to generate the avatar.

      • Optionaloptions: AvatarOptions

        Optional customization settings for the avatar.

        Defines the options for generating an SVG avatar.

        • OptionalbackgroundColor?: string

          The background color of the avatar (e.g., '#FF6600'). If not provided, a color will be deterministically generated from the username.

        • OptionalfontFamily?: string

          The font family for the initials. Defaults to 'Arial, sans-serif'.

        • OptionalfontSize?: number

          The font size for the initials. If not provided, it will be calculated based on avatar size.

        • Optionalheight?: number

          The height of the avatar in pixels. Defaults to 100.

        • OptionalinitialsLength?: number

          The maximum number of initials to display. Defaults to 2.

        • Optionalshape?: AvatarShape

          The shape of the avatar. Defaults to 'square'.

        • OptionalsvgAttributes?: { [key: string]: string }

          Additional SVG attributes to apply to the root element (e.g., { class: 'my-avatar' }). Values will be stringified directly.

        • Optionaltext?: string

          Text to explicitly display on the avatar instead of generated initials. If provided, initialsLength and username-based initial generation will be ignored.

        • OptionaltextColor?: string

          The color of the text (initials) on the avatar (e.g., '#FFFFFF'). If not provided, a contrasting color will be chosen based on the background.

        • Optionalwidth?: number

          The width of the avatar in pixels. Defaults to 100.

      Returns string

      The generated avatar SVG as a string.

      // Generate a basic square avatar
      const svg = generateAvatarSvg('johndoe');
      // Generate a circular avatar with custom colors
      const svg = generateAvatarSvg('janedoe', {
      shape: 'circle',
      backgroundColor: '#FF0000',
      textColor: '#FFFFFF'
      });
      // Generate an avatar with custom size and text
      const svg = generateAvatarSvg('bobsmith', {
      width: 200,
      height: 200,
      text: 'BS',
      fontSize: 48,
      svgAttributes: { class: 'custom-avatar' }
      });