Download the PHP package nicolas-gille/gravatar-lib without Composer
On this page you can find all versions of the php package nicolas-gille/gravatar-lib. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nicolas-gille/gravatar-lib
More information about nicolas-gille/gravatar-lib
Files in nicolas-gille/gravatar-lib
Package gravatar-lib
Short Description A simple library to integrate Gravatar service on app.
License MIT
Homepage http://nicolas-gille.fr
Informations about the package gravatar-lib
Gravatar Lib
Gravatar Lib is a small library to help integration of the gravatar service on your app.
Requirements
- PHP 7.0.0 or newer.
- hash() function must be available, along with md5 algorithm.
Usage
Installation
You can install Gravatar Lib with composer to execute the following command : $ composer require nicolas-gille/gravatar-lib
Yan can clone or download the source directly from Github, and install it on your app.
General example
Settings the size of the avatar.
Gravatar offer to change the size of your avatar.
By default, the value provide by Gravatar is 80 pixels, but, you can extends it at 2048 pixels.
To update the size of your avatar, use the method GravatarLib\Gravatar\Gravatar->setSize(int)
.
You can get an example of set size of the avatar below:
Nota Bene :
If you exceed the maximum or the minimum values, this method throw on \InvalidArgumentException
with the message
The size must be within 0 and 2048.
Settings the default image.
Gravatar provides several default avatar for people who don't have post their avatar.
Then, you can change the default image with these method GravatarLib\Gravatar\Gravatar->setDefaultImage(string)
.
The default value offer by Gravatar are : '404', 'mm', 'identicon', 'monsterid', 'retro', 'wavatar' and 'blank'.
Another way to set the default image is to send on correct uri on parameter of the method to get the image instead the default value offer by Gravatar.
To use you own avatar, you can leave the constructor without set the default value to use your avatar.
You can get an example of set default image below:
Nota Bene :
If you send on invalid url or a string not contains in Gravatar API, this method throw on \InvalidArgumentException
with the message The default image specified is not a valid URL or present as default value in Gravatar..
Settings the rating image
With Gravatar, you can block certain type of content like ESRB for USA or PEGI for Europe.
Then, if you block specific avatar, you can set the max rating allow in your app with the method
GravatarLib\Gravatar\Gravatar->setMaxRating(string)
.
The default value allowed in the method are : 'g', 'pg', 'r', 'x'.
You can get an example of set the rating max below:
Nota Bene :
If you send a string different to the valid value, this method throw on \InvalidArgumentException
with the message The rating specified is invalid. Use only "g", "pg", "r" or "x" value..
Settings secure uri.
In fact, Gravatar offer two way to get the image respectively in HTTP and in HTTPS.
By default, the library load the image via HTTP, but if you would, you can change this method by the method
GravatarLib\Gravatar\Gravatar->setSecureUri(bool)
.
Force default image
You can force the default image for every people who connect on your app with your email.
To force the default image, you can use the method GravatarLib\Gravatar\Gravatar->setForceDefaultImage(bool)
.
Twig integration
You can easily hook this library on you project build with Twig. In fact, to hook the library, you use a Twig_Environment object, and add it on it as a global attribute.
Then, to use it on your template, you must call the object gravatar with the method gravatar.uri(email)
to display the avatar.
In the example above, app.user.username
and app.user.email
contains respectively the username and the mail of the user.
License
This project is under MIT License.
Author
- Nicolas GILLE : [email protected]