Download the PHP package elijahcruz/avatar without Composer
On this page you can find all versions of the php package elijahcruz/avatar. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elijahcruz/avatar
More information about elijahcruz/avatar
Files in elijahcruz/avatar
Package avatar
Short Description Generate an avatar for your users using Gravatar and more
License MIT
Informations about the package avatar
PHP Avatars
Generate avatars quickly and easily through one simple to use class.
PHP Avatars was created with one VERY simple goal in mind, to be able to generate a URL for avatars, without memorizing the options that Avatar generators and providers such as Gravatar and UI Avatars provide.
COMING SOON: I will be adding built-in integration to Laravel, which will allow you to use a Facade to generate the URLs.
Requirements
There are ZERO requirements, other than needing PHP, needing Componser, and the website you're wanting to add PHP Avatars to. That's it.
Install
Installing is as simple as requiring it in Composer.
`
Usage
Using PHP Avatars is made to be very simple, however even though it's very simple, it has the ability to enable you to do everthing that each provider normally should allow you to do. For example, set the default in Gravatar, or set the background and color in UI Avatars.
Basic Example:
`
This is all is takes to load the users Gravatar. However, you can also have options as well. And there are multiple ways to do this:
`
As you may have noticed, when initializing PHP Avatar, the 2nd parameter is which generator you are using. You can also specify which type using it's method:
`
This allows you to switch between avatar generators quickly and easily. But what if each one uses different options, or you wanted to generate the URL again, but with a different size, no problem. Any options that aren't defined in the generator your currently using are ignored. Any that are, can be overwritten.
When using these, you can also add the new identifier with this.
`
`
You can also reset all options to a blank slate using the resetOptions() method. If you add an array to this, it will reset the array then add those options to it.
`
But what if you wanted to also change from using an email, to the person's name, so UI Avatars shows an actual name? No problem. Just use the newIdentifier() method;
`
The best part about all of this? They can be chained!
`
This is what makes PHP Avatars super simple, but VERY powerful.
This is all is takes to easily manage your avatars for your users.
Laravel Usage
The package now thankfully has Laravel support. You can now use a Facade that includes two amazing methods.
`
With the facade, you can still chain the existing methods that the framework agnostic version contains.
`
This makes is very easy to use inside of Laravel.
If you use UI Avatar more than gravatar, or want to change some other setting, you can always publish the config file:
`
Currently Supported Proviers
Meanwhile there are so many options in terms of providers out there, we're working on making as many as possible work with PHP Avatars, to give you the best possible package for this. Each provider's own options that they provide are included in PHP Avatars, to make things VERY simple.
Gravatar
Identifier Type: email
Options:
Option | Type | Accepts |
---|---|---|
default | string | mp, 404, identicon, monsterid, wavatar, retro, robohash, blank |
force_default | bool | true, false |
rating | string | g, pg, r, x |
size | int | Any integer |
extension | string | .jpg |
UI Avatar
Identifier Type: Name
Options:
Option | Type | Accepts | Default |
---|---|---|---|
size | int | 16-512 | 64 |
font_size | int | 0.1-1 | 0.5 |
length | int | Any int | 2 |
rounded | bool | true, false | false |
bold | bool | true, false | false |
background | string | any hex | f0e9e9 |
color | string | any hex | 8b5d5d |
uppercase | bool | true, false | true |
format | string | svg, png | Depends on Accepts Header, if SVG is in header, is SVG, else PNG |