Gravatar is a small library intended to provide easy integration of... Gravatar :) 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
use Gravatar\Gravatar;
use Gravatar\Enum\DefaultImage;
use Gravatar\Enum\Extension;
$avatar = Gravatar::image('email@example.com')
->size(120)
->defaultImage(DefaultImage::ROBOHASH)
->extension(Extension::JPG);
//...
echo $avatar;- Installation - Requirements and installation instructions
- Usage - How to use the library (helpers, base class, dedicated classes)
- Type-safe enums - Using enums and fluent shorthand methods
- Optional parameters - All available parameters and configurations
- Upgrade guide - Migration guides between major versions
- Changelog - Version history and changes
composer require forxer/gravatarRequires PHP 8.4 or newer. For older PHP versions, see Installation.
use Gravatar\Gravatar;
// Get a Gravatar image URL
echo Gravatar::image('email@example.com');
// output: //www.gravatar.com/avatar/5658ffccee7f0ebfda2b226238b1eb6e
// With parameters
$avatar = Gravatar::image('email@example.com')
->size(120)
->ratingPg()
->extensionWebp()
->defaultImageRobohash();
echo $avatar;
// Get a Gravatar profile URL
echo Gravatar::profile('email@example.com')->formatJson();Type-safe enums for better IDE support:
use Gravatar\Enum\Rating;
use Gravatar\Enum\Extension;
use Gravatar\Enum\DefaultImage;
$image->setMaxRating(Rating::PG)
->setExtension(Extension::WEBP)
->setDefaultImage(DefaultImage::ROBOHASH);Fluent shorthand methods for cleaner syntax:
$image->ratingPg()
->extensionWebp()
->defaultImageRobohash();Multiple usage patterns - helpers, static methods, or direct instantiation:
// Using helpers (define your own)
$avatar = gravatar('email@example.com')->size(120);
// Using static methods
$avatar = Gravatar::image('email@example.com')->size(120);
// Direct instantiation
$avatar = new Image('email@example.com');
$avatar->size(120);For more details, see the full documentation.
This library is licensed under the MIT license; you can find a full copy of the license itself in the file /LICENSE