Skip to main content
Back to packages
1,985 GitHub stars

laravolt/avatar

View on GitHub

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

Avatar::create('[email protected]')->toGravatar();
// Output: http://gravatar.com/avatar/0c5cbf5a8762d91d930795a6107b2ce5814a6ab26e60c7ec6b75bc81c7dfe3ee
 
Avatar::create('[email protected]')->toGravatar(['d' => 'identicon', 'r' => 'pg', 's' => 100]);
// 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

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.