forxer/laravel-gravatar

A library providing easy gravatar integration in a Laravel project.

Installs: 30 754

Dependents: 1

Suggesters: 0

Security: 0

Stars: 41

Watchers: 2

Forks: 10

Open Issues: 0

pkg:composer/forxer/laravel-gravatar

5.0.0 2025-11-17 13:27 UTC

README

Latest Stable Version Total Downloads License

Gravatar for Laravel

This package provides an easy Gravatar integration in a Laravel project.

use Gravatar\Enum\DefaultImage;
use Gravatar\Enum\Extension;

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

// With type-safe enums
$avatar = gravatar('email@example.com')
    ->size(120)
    ->defaultImage(DefaultImage::ROBOHASH)
    ->extension(Extension::JPG);

// With fluent shorthand methods
$avatar = gravatar('email@example.com')
    ->size(120)
    ->extensionJpg()
    ->defaultImageRobohash();

About this package

This Laravel package is built on top of the framework-agnostic forxer/gravatar library. It extends the base functionality by adding:

  • Laravel-specific features: Service providers, facades, helper functions (gravatar() and gravatar_profile()), and configuration
  • Extended classes: LaravelGravatar\Image extends Gravatar\Image, and LaravelGravatar\Profile extends Gravatar\Profile
  • Additional Laravel integrations: Eloquent casts, preset configurations, and base64 conversion with Laravel's HTTP client
  • Full support for PHP 8.4 features: Property hooks, type-safe enums, and fluent shorthand methods from the parent library

All the core Gravatar functionality from the parent library is available in this package.

Documentation

Complete documentation is available in the docs directory:

Requirements

  • PHP 8.4+
  • Laravel 12.0+

For earlier versions:

Quick Installation

composer require forxer/laravel-gravatar

The service provider is automatically registered via package discovery.

Quick Start

// Simple usage with helper
<img src="{{ gravatar($user->email) }}" alt="Avatar">

// With configuration
$avatar = gravatar('user@example.com')
    ->size(120)
    ->extensionWebp()
    ->defaultImageRobohash();

// Using presets
$avatar = gravatar($user->email, 'small');

// With Eloquent casts
class User extends Model
{
    protected $casts = [
        'email' => GravatarImage::class.':medium',
    ];
}

// In Blade
<img src="{{ $user->email }}" alt="Avatar">

Key Features

  • Helper functions - gravatar() and gravatar_profile() for quick access
  • Facade support - Gravatar::image() and Gravatar::profile()
  • Eloquent casts - Seamless model integration
  • Preset configurations - Define reusable avatar settings with automatic validation
  • Enum-based validation - Preset values validated against type-safe enums at runtime
  • Base64 conversion - Convert avatars to data URLs
  • PHP 8.4 property hooks - Direct property access with validation
  • Type-safe enums - Rating, Extension, DefaultImage, ProfileFormat
  • Fluent shorthand methods - extensionWebp(), ratingPg(), defaultImageRobohash()

Version History

See CHANGELOG.md for all changes.

Upgrading

See UPGRADE.md for upgrade instructions between major versions.

License

This package is open-source software licensed under the MIT license.