forxer / gravatar
A library providing easy gravatar integration.
Installs: 195 241
Dependents: 9
Suggesters: 0
Security: 0
Stars: 29
Watchers: 1
Forks: 3
Open Issues: 0
pkg:composer/forxer/gravatar
Requires
- php: ^8.4
Requires (Dev)
- laravel/pint: ^1.25.1
- rector/rector: ^2.2.8
README
Gravatar
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;
Documentation
- 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
Quick Start
Installation
composer require forxer/gravatar
Requires PHP 8.4 or newer. For older PHP versions, see Installation.
Basic Usage
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();
Key Features
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.
License
This library is licensed under the MIT license; you can find a full copy of the license itself in the file /LICENSE