API reference
A summary of the public classes. All live under Renfordt\AvatarSmithy.
Avatar
Static factory.
| Method | Returns | Description |
|---|---|---|
Avatar::engine(string $engine) | AvatarBuilder | Start a builder with a named primary engine. |
Avatar::for(mixed $user) | AvatarBuilder | Start a builder, pre-filling seed/name from a user. |
for() reads email/name properties or getEmail()/getName() methods on an
object (methods win when both exist), or email/name keys on an array. The
email is used as the seed.
AvatarBuilder
Fluent configuration and generation. Constructor:
__construct(?string $engine = null, LoggerInterface $logger = new NullLogger()).
Selected methods:
| Method | Returns | Description |
|---|---|---|
try(string) | self | Set primary engine, or append a fallback. |
fallbackTo(string) | self | Append a fallback engine. |
seed(string) | self | Set the seed. |
name(string) | self | Set the display name. |
size(int) | self | Set output size (8–2048). |
setLogger(LoggerInterface) | self | Set a PSR-3 logger. |
debugMode(bool) | self | Rethrow the first engine failure. |
getLastErrors() | array | Failures from the last generate() call. |
generate() | GeneratedAvatar | Run the engine chain. |
Option setters are listed in The builder.
GeneratedAvatar
Implements Stringable. Constructor:
__construct(string $content, string $contentType = 'image/svg+xml', ?string $name = null, int $size = 200).
| Method | Returns | Description |
|---|---|---|
alt(string) | self | Set alt text. |
toHtml() | string | <img> tag. |
accessibleHtml() | string | <img> with role/aria-label. |
toBase64() | string | data: URI. |
toUrl() | string | Remote URL, else data URI. |
toSvg() | string | Raw content. |
toPng(?int, ?int, int) | GeneratedAvatar | PNG conversion. |
toJpg(?int, ?int, int) | GeneratedAvatar | JPG conversion. |
toWebp(?int, ?int, int) | GeneratedAvatar | WebP conversion. |
save(string) | bool | Write content to a path. |
getContent() | string | Raw content. |
getContentType() | string | MIME type. |
__toString() | string | Raw content. |
Http\AvatarResponder
final readonly. Constructor takes a GeneratedAvatar.
| Method | Returns | Description |
|---|---|---|
toResponse() | mixed | Send as an HTTP response. |
download(string $filename) | mixed | Send as an attachment. |
stream(int $chunkSize, bool $headers) | void | Write the body in chunks. |
Support\Name
Helper used by local engines. Name::make(string) constructs it.
| Method | Returns | Description |
|---|---|---|
getInitials() | string | Uppercase, UTF-8-aware initials. |
getHexColor(int $offset=0) | HexColor | Color derived from the MD5 hash of the name. |
getName() | string | The original name. |
getHash() | string | MD5 hash of the name. |
Converters\ImageConverter
Static conversion helpers used by GeneratedAvatar. See
Image conversion.
Engines\EngineInterface
Contract for engines. See Custom engines.