Skip to main content

Initials engine

Name: initials. Output: SVG. Renders the user's initials over a colored shape.

The initials and color are derived from the name when set, otherwise from the seed. The background and foreground are two lightness variants of the same hue, which is derived from the hash of the name/seed.

Avatar::engine('initials')
->name('John Doe')
->size(256)
->shape('circle')
->fontWeight('bold')
->generate();

Declining

The engine returns null (declines, triggering the fallback chain) when there are no usable initials — an empty name/seed, or one that yields only 0.

Initials are the first character of each space-separated word, uppercased, and UTF-8 aware.

Options

OptionMethodTypeDefault
Shapeshape()stringcircle
Foreground lightnessforegroundLightness()float0.35
Background lightnessbackgroundLightness()float0.8
Font sizefontSize()intcomputed from size and initials
Font weightfontWeight()stringnormal

shape accepts circle, square, or hexagon. The font family is Segoe UI, Helvetica, sans-serif.

A rotation option (degrees) is read for the hexagon shape; it is not exposed by a dedicated builder method but is read from the option bag if set.

When fontSize is not supplied, it scales with the avatar size and the number of initials.