Video
Description
Display unique avatar for any user based on their (initials) name
Output as base64
//this will output data-uri (base64 image data)//something like data:image/png;base64,iVBORw0KGg....Avatar::create('Joko Widodo')->toBase64(); //use in view//this will display initials JW as an image<img src="{{ Avatar::create('Joko Widodo')->toBase64() }}" />
Save as file
Avatar::create('Susilo Bambang Yudhoyono')->save('sample.png');Avatar::create('Susilo Bambang Yudhoyono')->save('sample.jpg', 100); // quality = 100
Output as Gravatar
// Output: http://gravatar.com/avatar/0c5cbf5a8762d91d930795a6107b2ce5814a6ab26e60c7ec6b75bc81c7dfe3ee // Output: http://gravatar.com/avatar/0c5cbf5a8762d91d930795a6107b2ce5814a6ab26e60c7ec6b75bc81c7dfe3ee?d=identicon&r=pg&s=100
Gravatar parameter reference: https://docs.gravatar.com/api/avatars/images/
Output as SVG
Avatar::create('Susilo Bambang Yudhoyono')->toSvg();
You may specify custom font-family for your SVG text.
<head> <!--Prepare custom font family, using Google Fonts--> <link href="https://fonts.googleapis.com/css?family=Laravolt" rel="stylesheet"> <!--OR--> <!--Setup your own style--> <style> @font-face { font-family: Laravolt; src: url({{ asset('fonts/laravolt.woff')) }}); } </style></head>
Avatar::create('Susilo Bambang Yudhoyono')->setFontFamily('Laravolt')->toSvg();
You may make the SVG responsive. This excludes the height and width attributes.
Avatar::create('Susilo Bambang Yudhoyono')->setResponsive()->toSvg();
Related Content on Laravel Daily
Video
Recent Courses on Laravel Daily
[NEW] Practical Laravel Security: Packages, Secrets, Supply-Chain Attacks
7 lessons
43 min read
How to Build Laravel 13 API From Scratch
30 lessons
1 h 23 min
How to Structure Laravel 13 Projects
16 lessons
1 h 32 min read