Skip to content

Commit 3bef45c

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 5a9b352 + f2971db commit 3bef45c

5 files changed

+37
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,28 @@ Will yield:
142142

143143
*Rounded for appearance; the actual avatar is a filled square*
144144

145+
## Font Awesome Support
146+
147+
The package supports FontAwesome (v5) and already distributes the free version as `otf` format (see `/fonts` folder).
148+
149+
However, when using FontAwesome you may want to display one specific icon instead of the user's initials. This package, therefore, provides a handy `glyph($code)` method to be used along with FontAwesome.
150+
151+
First, you need to "find" the respective unicode for the glyph you want to insert. For example, you may want to display a typical "user" icon (unicode: `f007`). The unicode is located near the name of the icon (e.g., see here the user icon as an example here: [https://fontawesome.com/icons/user](https://fontawesome.com/icons/user) ).
152+
153+
An example for rendering a red avatar with a white "user" glyph would look like this:
154+
155+
```php
156+
// note that we
157+
// 1) use glyph() instead of name
158+
// 2) change the font to FontAwesome!
159+
return $avatar->glyph('f007')
160+
->font('/fonts/FontAwesome5Free-Regular-400.ttf')
161+
->color('#fff')
162+
->background('#ff0000')
163+
->generate()
164+
->stream('png', 100);
165+
```
166+
145167
## Requirements
146168
* PHP 5.6, 7.0, 7.1 or 7.2
147169
* Fileinfo Extension (from intervention/image)

src/InitialAvatar.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ public function name($nameOrInitials)
4848
return $this;
4949
}
5050

51+
/**
52+
* Transforms a unicode string to the proper format
53+
*
54+
* @param string $char the code to be converted (e.g., f007 would mean the "user" symbol)
55+
*
56+
* @return $this
57+
*/
58+
public function glyph($char)
59+
{
60+
$uChar = json_decode(sprintf('"\u%s"', $char));
61+
$this->name($uChar);
62+
63+
return $this;
64+
}
65+
5166
/**
5267
* Set the length of the generated initials.
5368
*
343 KB
Binary file not shown.
108 KB
Binary file not shown.
337 KB
Binary file not shown.

0 commit comments

Comments
 (0)