PHPackages                             hpsweb/gravatar - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hpsweb/gravatar

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hpsweb/gravatar
===============

A library providing easy gravatar integration.

4.0.4(1y ago)022MITPHPPHP ^8.0

Since May 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/OoHerbethoO/gravatar)[ Packagist](https://packagist.org/packages/hpsweb/gravatar)[ RSS](/packages/hpsweb-gravatar/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/5813676fa82b3f8556be80fd89bd4aceeb3e41d7ed1814e236adea8cb3b3253c/687474703a2f2f706f7365722e707567782e6f72672f666f727865722f67726176617461722f76)](https://packagist.org/packages/forxer/gravatar)[![Total Downloads](https://camo.githubusercontent.com/479578e8fe3b9b574509ca8c64d64f7c0ee2165c3ef9f43e07a5548d76b08593/687474703a2f2f706f7365722e707567782e6f72672f666f727865722f67726176617461722f646f776e6c6f616473)](https://packagist.org/packages/forxer/gravatar)[![License](https://camo.githubusercontent.com/f18f8f1727c27c4bc0ba1b3d266f722e135e00ebf5e2bd61b725697c5258ae68/687474703a2f2f706f7365722e707567782e6f72672f666f727865722f67726176617461722f6c6963656e7365)](https://packagist.org/packages/forxer/gravatar)

Gravatar
========

[](#gravatar)

Gravatar is a small library intended to provide easy integration of... [Gravatar](https://gravatar.com) :) It will help you generate the URL for Gravatar images and profiles in many ways.

To use it in a **Laravel project**, please look at: **[laravel-gravatar](https://github.com/forxer/laravel-gravatar)**

```
$avatar = gravatar('email@example.com')
    ->size(120)
    ->defaultImage('robohash')
    ->extension('jpg');
//...
echo $avatar;
```

Index
-----

[](#index)

- [Installation](#installation)
    - [Requirements](#requirements)
    - [With Composer](#with-composer)
    - [Without Composer](#without-composer)
- [Usage](#usage)
    - [Use helpers](#use-helpers)
    - [Use the Gravatar base class](#use-the-gravatar-base-class)
        - [Single Gravatar image/profile](#single-gravatar-imageprofile)
        - [Multiples Gravatar images/profiles](#multiples-gravatar-imagesprofiles)
    - [Instanciate the dedicated classes](#instanciate-the-dedicated-classes)
- [Mandatory parameter](#mandatory-parameter)
- [Optional parameters](#optional-parameters)
    - [Gravatar image size](#gravatar-image-size)
    - [Default Gravatar image](#default-gravatar-image)
    - [Gravatar image max rating](#gravatar-image-max-rating)
    - [Gravatar image file-type extension](#gravatar-image-file-type-extension)
    - [Force to always use the default image](#force-to-always-use-the-default-image)
    - [Gravatar profile format](#gravatar-profile-format)
- [License](#license)

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

[](#installation)

### Requirements

[](#requirements)

- PHP 8.0.0 or newer

If you want to use it with a version earlier than PHP 8, please use [version 2](https://github.com/forxer/gravatar/tree/2.1).

### With Composer

[](#with-composer)

The easiest way to install Gravatar is via [Composer](http://getcomposer.org/). Run the following command in the root of your project:

```
composer require hpsweb/gravatar

```

### Without Composer

[](#without-composer)

You should use composer, it's so convenient. However, if you really do not want, or can not, you can [download the latest version](https://github.com/forxer/gravatar/releases/latest) and unpack the archive.

Then, you do what it takes to use it with your own autoloader. The examples below use the Composer autoloader.

[Back to top ^](#gravatar)

Usage
-----

[](#usage)

There are many ways to use this library:

- Use helpers fonctions
- Use the Gravatar base class with its `Gravatar::image()` and `Gravatar::profile()` methods
- Instantiate the dedicated classes `Gravatar\Image()` and `Gravatar\Profile()`

All of these ways return instances of `Gravatar\Image` and `Gravatar\Profile` that allow you to define specific settings/parameters as needed.

Whatever method you use, you could use the `url()` method to retrieve it. Or display the URL directly because they implement the `__toString()` method.

### Use helpers

[](#use-helpers)

The easiest way to use this library is to use the helper functions.

Since version 4, in order to avoid conflicts with other packages, we no longer define the `gravatar()` and `gravatar_profile()` helpers. It's up to you to do this in your app with names that work for you and don't conflict with others. Here's how to do it; it's simple.

In a file dedicated to the helper functions, define the version 3 functions using the names that suit you.

```
