Download the PHP package naas/php-initial-avatar-generator without Composer
On this page you can find all versions of the php package naas/php-initial-avatar-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-initial-avatar-generator
Generate avatars with initials
Ever seen those avatars (basically everywhere) that has your initials — mine would be LR; Lasse Rafn — well this package allows you to generate those, in a simple manner.
Backers
Thank you to all our backers! 🙏 [Become a backer]
Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
There's also a api you can use: https://ui-avatars.com
Installation
You just require using composer and you're good to go! ` Rad, and long, package name.. huh? Sorry. I'm not very good with names.
Usage
As with installation, usage is quite simple. Generating a image is done by running: ``
Thats it! The method will return a instance of Image from Intervention so you can stream, download or even encode the image: `` You can also just pass along the initials, and it will use those. Should you just include a first name, it will use the first two letters of it.
SVG generation
``
Supported methods and parameters
Of cause, passing a name is not the only thing this sweet thing does!
Name (initials) - default: JD
``
AutoFont - default: false
Will detect language script (using lasserafn/php-string-script-language) and use a font that supports it.
``
Width - default: 48
``
Height - default: 48
``
Size - default: 48 (proxy for $avatar->width(X)->height(X)
)
``
Background color - default: #f0e9e9
``
Font color - default: #8b5d5d
``
Font file - default: /fonts/OpenSans-Regular.ttf
Two fonts with two variants are included:
- /fonts/OpenSans-Regular.ttf
- /fonts/OpenSans-Semibold.ttf
- /fonts/NotoSans-Bold.ttf
- /fonts/NotoSans-Regular.ttf
The method will look for the font, if none found it will append __DIR__
and try again, and if not it will default to the first GD Internal Font.
If you input an integer between 1 and 5, it will use a GD Internal font as per that number.
``
Font name (for SVGs) - default: Open Sans, sans-serif
``
Length - default: 2
``
Switching driver - default: gd
``
Rounded - default: false
``
Smooth - default: false
Makes rounding smoother with a resizing hack. Could be slower.
``
If you are going to use rounded()
, you want to use smooth()
to avoid pixelated edges. Disabled by default because it COULD be slower.
I would recommend just rounding with CSS.
Font Size - default: 0.5
`` If the Image size is 50px and fontSize is 0.5, the font size will be 25px.
Chaining it all together
We will not use the ->font() method in this example; as I like the regular one.
``
Now, using that in a image (sized 48x48 pixels for retina): ` Will yield:
Rounded for appearance; the actual avatar is a filled square
Font Awesome Support
The package supports FontAwesome (v5) and already distributes the free version as otf
format (see /fonts
folder).
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.
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 ).
An example for rendering a red avatar with a white "user" glyph would look like this:
Requirements
- PHP +7.0
- Fileinfo Extension (from intervention/image)
Script/Language support
Some letters are not supported by the default font files, so I added some fonts to add support. You must use autoFont()
to enable this feature. Supported are:
- Arabic
- Armenian
- Bengali
- Georgian
- Hebrew
- Mongolian
- Chinese
- Thai
- Tibetan
Contributors
Open Source is best when supported by a community. Any size of contribution is very appreciated.
Supported Image Libraries (from intervention/image)
- GD Library (>=2.0)
- Imagick PHP extension (>=6.5.7)
All versions of php-initial-avatar-generator with dependencies
ext-json Version *
intervention/image Version ^2.3
lasserafn/php-initials Version ^3.0
lasserafn/php-string-script-language Version ^0.3.0
meyfa/php-svg Version ^0.9.0
overtrue/pinyin Version ^4.0