PHPackages                             ballen/gravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ballen/gravel

ActiveLibrary

ballen/gravel
=============

Gravel is a PHP library which provides easy access to get and display Gravatars.

3.0.3(3y ago)13485↓100%2[1 PRs](https://github.com/allebb/gravel/pulls)MITPHPPHP ^7.3|^8.0

Since Jan 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/allebb/gravel)[ Packagist](https://packagist.org/packages/ballen/gravel)[ Docs](https://github.com/allebb/gravel)[ RSS](/packages/ballen-gravel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (12)Used By (0)

Gravel
======

[](#gravel)

[![Build](https://github.com/allebb/gravel/workflows/build/badge.svg)](https://github.com/allebb/gravel/actions)[![Code Coverage](https://camo.githubusercontent.com/b38a03cfe8a91de4227de338c77c586aee0ff45027f0f23ea7cd91279a693e9d/68747470733a2f2f636f6465636f762e696f2f67682f616c6c6562622f67726176656c2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/allebb/gravel)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a18e746c1646fc59adc4cb910148f8daccbf0ec741e8223e689f2b880dd1b049/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c6c6562622f67726176656c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/allebb/gravel/?branch=master)[![Code Climate](https://camo.githubusercontent.com/b5ae3c7fc2870d591cd2d36afafeaa5ee10fe0cc853a480b7a7bf20aebd2e99b/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f616c6c6562622f67726176656c2f6261646765732f6770612e737667)](https://codeclimate.com/github/allebb/gravel)[![Latest Stable Version](https://camo.githubusercontent.com/b65b31599cfefbb0786f47ef1f7f86f515f836fa895b834764ce1956c012b7b9/68747470733a2f2f706f7365722e707567782e6f72672f62616c6c656e2f67726176656c2f762f737461626c65)](https://packagist.org/packages/ballen/gravel)[![Latest Unstable Version](https://camo.githubusercontent.com/4fbd59a29c0c2edb916e4aa0be18c39799d0a1d573af7547e37a072e58543861/68747470733a2f2f706f7365722e707567782e6f72672f62616c6c656e2f67726176656c2f762f756e737461626c65)](https://packagist.org/packages/ballen/gravel)[![License](https://camo.githubusercontent.com/649bdf321fff5333a4d9fa2244f7c67d3409aa1a55802919d948fc2f7c90a8d2/68747470733a2f2f706f7365722e707567782e6f72672f62616c6c656e2f67726176656c2f6c6963656e7365)](https://packagist.org/packages/ballen/gravel)

[Gravel](https://github.com/allebb/gravel) is a PHP library for working with [Gravatar](http://www.gravatar.com) avatars.

Gravel is written and maintained by [Bobby Allen](http://bobbyallen.me), the library is licensed under the [MIT license](LICENSE).

Requirements
------------

[](#requirements)

This library is developed and tested for PHP 7.3+

This library is unit tested against PHP 7.3, 7.4, 8.0, 8.1 and 8.2!

If you need to use an older version of PHP, you should instead install the 2.x version of this library (see below for details).

License
-------

[](#license)

This client library is released under the MIT license, a [copy of the license](https://github.com/allebb/gravel/blob/master/LICENSE) is provided in this package.

Installation
------------

[](#installation)

The recommended way of installing the latest version of Gravel is via. [Composer](http://getcomposer.org); To install using Composer type the following command at the console:

```
composer require ballen/gravel
```

You can also manually download the latest version as a [zip](https://github.com/allebb/gravel/archive/master.zip) or [tar.gz](https://github.com/allebb/gravel/archive/master.tar.gz) archive of the library from GitHub and 'include' the `Gravatar.php` script (library) and use it standalone if you wish.

**If you need to use an older version of PHP, version 2.x.x supports PHP 5.3, 5.4, 5.5, 5.6, 7.0, 7.1 and 7.2, you can install this version using Composer with this command instead:**

```
composer require ballen/gravel ^2.0
```

### Laravel Integration

[](#laravel-integration)

Gravel has optional support for [Laravel](http://www.laravel.com) 4.x, 5.x, 6.x, 7.x and 8.x; it comes with a **Service Provider** which will register the **Facade** for easy integration.

On Laravel 7.x and 8.x this will be auto-discovered and no need to add it to the `config/app.php` `$providers` array!

If you are using an earlier version of Laravel you will need to manually enable this, which can be achieved by opening your Laravel application's configuration file `config/app.php` (or `app/config/app.php` if you are using Laravel 4.x) and add the following lines.

In the `$providers` array add the service providers for this package.

```
Ballen\Gravel\GravelServiceProvider::class,
```

The Gravatar package will now be autoloaded by the Laravel framework (via. Composer) and use of the library is as simple...

Example usage
-------------

[](#example-usage)

If you have installed the library using Composer or manually you can (as long as your application already `requires` or `includes` the composer `autoload.php`) then you can instantiate a new object instance and use it immediately in your application like so:

```
use Ballen\Gravel\Gravatar;

$avatar = new Gravatar('bobbyallen.uk@gmail.com');
$avatar->setSize(100); // We want a 100x100px sized avatar instead of the default 120x120px

/**
* You can then obtain the avatar URL either by using the buildGravatarUrl() method or utilising
* the __toString() class method like so:
*/
