PHPackages                             gleez/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. gleez/gravatar

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

gleez/gravatar
==============

A lightweight PHP library providing easy gravatar integration

1.0.2(11y ago)643BSD-3-ClausePHPPHP &gt;=5.3.29

Since May 2Pushed 9y ago2 watchersCompare

[ Source](https://github.com/sergeyklay/gleez-gravatar)[ Packagist](https://packagist.org/packages/gleez/gravatar)[ Docs](https://github.com/sergeyklay/gleez-gravatar/releases)[ RSS](/packages/gleez-gravatar/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

Gleez Gravatar
==============

[](#gleez-gravatar)

[![Build Status](https://camo.githubusercontent.com/940b8036fa629c5d7e8aa2e2d0f36b7eba3c388d62a0472b42d0b52da17bbc99/68747470733a2f2f7472617669732d63692e6f72672f7365726765796b6c61792f676c65657a2d67726176617461722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sergeyklay/gleez-gravatar)[![Dependency Status](https://camo.githubusercontent.com/311073a9f7da160de37828d1824602b83707adc8afd549d10ba1c0a43bab9db9/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3533363363313165666530643037313934663030303030312f62616467652e706e67)](https://www.versioneye.com/user/projects/5363c11efe0d07194f000001)

What Is Gleez Gravatar?
-----------------------

[](#what-is-gleez-gravatar)

[Gravatar's](http://gravatar.com/) are universal avatars available to all web sites and services. Users must register their email addresses with Gravatar before their avatars will be usable in your project.

The Gleez Gravatar component provides an easy way to retrieve a user's profile image from [Gravatar](http://gravatar.com/) based on a given email address. If the email address cannot be matched with a Gravatar account, an alternative will be returned based on the `Gravatar::$defaultImage` setting.

Users with gravatars can have a default image if you want to.

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

[](#requirements)

### Tested PHP versions

[](#tested-php-versions)

- 5.3.x
- 5.4.x
- 5.5.x
- 5.6.x
- 7
- hhvm

### Additional requirements

[](#additional-requirements)

- PHPUnit 4.0.0 or higher (for testing)
- PHP\_CodeSniffer 2.x or higher (for testing)

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

[](#installation)

**Git way**

```
$ git clone https://github.com/sergeyklay/gleez-gravatar
```

**Composer way**

Download and install composer from :

```
$ curl -sS https://getcomposer.org/installer | php
```

Add the following to your project `composer.json` file:

```
{
    "require": {
        "gleez/gravatar": "dev-master"
    }
}
```

When you're done just run

```
$ php composer.phar install
```

and the package is ready to be used. Another way, if you already have composer:

```
$ composer require --prefer-source gleez/gravatar:dev-master
```

**Direct zipball download**

Getting Started
---------------

[](#getting-started)

```
// Some preparation with your class autoloader
// ...

// Get Gravatar instance
$gravatar = Gleez\Gravatar\Gravatar::getInstance();

// Setting default image, maximum size and maximum allowed Gravatar rating
$gravatar->setDefaultImage('retro')
         ->setSize(220)
         ->setRating('pg');

// Build the Gravatar URL based on the configuration and provided email address
$avatar = $gravatar->buildURL('john@doe.com');
```

Configuration
-------------

[](#configuration)

### Gravatar size

[](#gravatar-size)

Gravatar allows avatar images ranging from 0px to 2048px in size. With using 0px size, images from Gravatar will be returned as 80x80px.

Example:

```
// Set gravatars size 64x64px
$gravatar->setSize(64);

// Set gravatars size 100x100px
$gravatar->setSize('100');
```

**WARNING**: If an invalid size (less than 0, greater than 2048) or a non-integer value is specified, this method will throw an exception of class `\InvalidArgumentException`.

### Default Image

[](#default-image)

Gravatar provides several pre-fabricated default images for use when the email address provided does not have a gravatar or when the gravatar specified exceeds your maximum allowed content rating. In addition, you can also set your own default image to be used by providing a valid URL to the image you wish to use.

There are a few conditions which must be met for default image URL:

- **MUST** be publicly available (e.g. cannot be on an intranet, on a local development machine, behind HTTP Auth or some other firewall etc). Default images are passed through a security scan to avoid malicious content
- **MUST** be accessible via HTTP or HTTPS on the standard ports, 80 and 443, respectively
- **MUST** have a recognizable image extension (jpg, jpeg, gif, png)
- **MUST NOT** include a query string (if it does, it will be ignored)

Possible values:

- `404` — do not load any image if none is associated with the email, instead return an HTTP 404 (File Not Found) response
- `mm` — (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email)
- `identicon` — a geometric pattern based on an email
- `monsterid` — a generated 'monster' with different colors, faces, etc
- `wavatar` — generated faces with differing features and backgrounds
- `retro` — awesome generated, 8-bit arcade-style pixelated faces
- `blank` — a transparent PNG image
- boolean false — if using the default gravatar image
- Image URL

Example:

```
// boolean false for the gravatar default
$gravatar->setDefaultImage(false);

// string specifying a recognized gravatar "default"
$gravatar->setDefaultImage('identicon');

// string with image URL
$gravatar->setDefaultImage("http://example.com/your-default-image.png");
```

**WARNING**: If an invalid default image is specified (both an invalid prefab default image and an invalid URL is provided), this method will throw an exception of class `\InvalidArgumentException`.

### Using secure connection

[](#using-secure-connection)

Should we use the secure (HTTPS) URL base? If your site is served over HTTPS, you'll likely want to serve gravatars over HTTPS as well to avoid "mixed content warnings".

Example:

```
// Enable secure connections:
$gravatar->enableSecureURL();

// Disable secure connections:
$gravatar->disableSecureURL();
```

To check to see if you are using "secure images" mode, call the method `Gravatar::useSecureURL()`, which will return a boolean value regarding whether or not secure images mode is enabled.

### Gravatar Rating

[](#gravatar-rating)

Gravatar provides four levels for rating avatars by, which are named similar to entertainment media ratings scales used in the United States.

Possible values:

- `g` — suitable for display on all websites with any audience type
- `pg` — may contain rude gestures, provocatively dressed individuals, the lesser swear words, or mild violence
- `r` — may contain such things as harsh profanity, intense violence, nudity, or hard drug use
- `x` — may contain hardcore sexual imagery or extremely disturbing violence

By default, the Gravater rating is `g`.

Example:

```
$gravatar->setRating('PG');
```

**WARNING**: If an invalid maximum rating is specified, this method will throw an exception of class `\InvalidArgumentException`.

### Force Default

[](#force-default)

If for some reason you wanted to force the default image to always load, you can enable or disable it.

Example:

```
// Enable
$gravatar->enableForceDefault();

// Disable
$gravatar->disableForceDefault();
```

To check to see if you are using "Force Default" mode, call the method `Gravatar::useForceDefault()`, which will return a boolean value.

Contributing
------------

[](#contributing)

So, you want to contribute to the Gleez Gravatar project? Well of course you do! I guess that's pretty clear. I mean, anyone could tell, right?

Some things to watch out for:

- Please do PR to `next` branch
- Make sure that the code you write fits with the general style and coding standarts of the [Accepted PHP Standards](http://www.php-fig.org/psr/)
- Your code should be easy to understand, maintainable, and modularized
- Please *test* your changes before submitting to make sure that not only they work, but have not broken other parts of the Gleez Gravatar
- If you do any API changes please follow [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html)

Tests
-----

[](#tests)

To run the tests at the command line, go to the `tests` directory and run `phpunit`:

```
$ composer install --dev --prefer-source
$ phpunit \
--configuration tests/phpunit.xml.dist \
--coverage-text \
--coverage-clover ../build/logs/clover.xml \
--coverage-html   ../build/report
```

For additional information see [PHPUnit The Command-Line Test Runner](http://phpunit.de/manual/current/en/textui.html)

License
-------

[](#license)

Licensed under the [Gleez CMS License](http://gleezcms.org/license). © Gleez Technologies

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~326 days

Total

2

Last Release

4067d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

1.0.2PHP &gt;=5.3.29

### Community

Maintainers

![](https://www.gravatar.com/avatar/97049a4bd2f9716e97749f93fe32f8da0a3eeda4192772dec73a6a2531294cea?d=identicon)[klay](/maintainers/klay)

![](https://www.gravatar.com/avatar/d3eb0626edd74a20f76b2b6f1fdb0e48cb1a18936c093ca67dccdfbd14bca868?d=identicon)[sandeepone](/maintainers/sandeepone)

---

Top Contributors

[![sergeyklay](https://avatars.githubusercontent.com/u/1256298?v=4)](https://github.com/sergeyklay "sergeyklay (35 commits)")

---

Tags

gravataravatargleez

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/gleez-gravatar/health.svg)

```
[![Health](https://phpackages.com/badges/gleez-gravatar/health.svg)](https://phpackages.com/packages/gleez-gravatar)
```

###  Alternatives

[laravolt/avatar

Turn name, email, and any other string into initial-based avatar or gravatar.

2.0k5.4M31](/packages/laravolt-avatar)[yohang88/letter-avatar

Generate user avatar using name initials letter.

126529.5k2](/packages/yohang88-letter-avatar)[cebe/yii2-gravatar

Gravatar Widget for Yii 2

441.8M35](/packages/cebe-yii2-gravatar)[arcanedev/gravatar

A library providing easy gravatar integration/generation (Laravel supported).

1986.8k](/packages/arcanedev-gravatar)[forxer/gravatar

A library providing easy gravatar integration.

35202.0k8](/packages/forxer-gravatar)[artdarek/avatarer

Avatarer - Social media avatars for Laravel 5

1015.4k](/packages/artdarek-avatarer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
