Display a unique avatar for any user based on their (initials) name.
This Module is inspired by [Laravolt](https://github.com/laravolt/avatar)
Copy // This will output data-uri (base64 image data), e.g., data:image/png;base64,iVBORw0KGg...
Avatar::create('Joko Widodo')->toBase64();
// Use in view to display initials as an image
<img src="{{ Avatar::create('Joko Widodo')->toBase64() }}" />
Copy Avatar::create('Susilo Bambang Yudhoyono')->save('sample.png');
Avatar::create('Susilo Bambang Yudhoyono')->save('sample.jpg', 100); // Quality = 100
Copy Avatar::create('uyab@example.net')->toGravatar();
// Output: http://gravatar.com/avatar/...
Avatar::create('uyab@example.net')->toGravatar(['d' => 'identicon', 'r' => 'pg', 's' => 100]);
// Output: http://gravatar.com/avatar/...&d=identicon&r=pg&s=100
Gravatar parameter reference
Copy Avatar::create('Susilo Bambang Yudhoyono')->toSvg();
You may specify a custom font family for your SVG text.
Copy <head>
<!-- Using Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Inter" rel="stylesheet">
<!-- OR Setup custom style -->
<style>
@font-face {
font-family: Inter;
src: url({{ asset('fonts/inter.woff') }});
}
</style>
</head>
Copy Avatar::create('Susilo Bambang Yudhoyono')->setFontFamily('Inter')->toSvg();
Copy Avatar::create('Abdul Somad')->getImageObject();
Returns an instance of the Intervention image object, enabling further processing.
The library tries to render initials as supplied. For non-ASCII characters (e.g., ā, Ě), their visibility depends on font support. Alternatively, non-ASCII characters can be converted to their closest ASCII counterparts using Stringy.
Copy Avatar::create('Soekarno')->setDimension(100); // Width = Height = 100 pixels
Avatar::create('Soekarno')->setDimension(100, 200); // Width = 100, Height = 200
Avatar::create('Soekarno')->setBackground('#001122');
Avatar::create('Soekarno')->setForeground('#999999');
Avatar::create('Soekarno')->setFontSize(72);
Avatar::create('Soekarno')->setFont('/path/to/font.ttf');
Avatar::create('Soekarno')->setBorder(1, '#aabbcc'); // Size = 1, Color = #aabbcc
Avatar::create('Soekarno')->setBorder(1, '#aabbcc', 10); // Border radius = 10 (for SVG only)
Avatar::create('Soekarno')->setShape('square');
// Since v3.0.0
Avatar::create('Soekarno')->setTheme('colorful'); // Set exact theme
Avatar::create('Soekarno')->setTheme(['grayscale-light', 'grayscale-dark']); // Random theme from options
// Chaining
Avatar::create('Habibie')->setDimension(50)->setFontSize(18)->toBase64();