ornicar/gravatar-bundle
A lightweight Symfony bundle for integrating Gravatar avatars. It provides a Twig helper and service to generate Gravatar URLs with configurable size, rating, and default image settings, making it easy to add user profile avatars to your templates and services.
The first thing to confront: ornicar/gravatar-bundle (published as henrikbjorn/gravatar-bundle) is a Symfony bundle, not a Laravel package. There is no service provider, no facade, no publishable config/*.php, and no package auto-discovery. Installing it in a Laravel app gets you an autoloadable class — and then you're on your own to wire it into the container and views.
Minimal path for a Laravel developer:
https://www.gravatar.com/avatar/{md5(lower(trim(email)))} plus query params: s (size), d (default image), r (rating), f (force default).Gravatar service and its Twig gravatar() helper — it's a useful spec for parameter names, ordering, and defaults.app/Support/Gravatar.php rather than adopting the bundle.First use case: an avatar in a Blade view.
<img src="{{ gravatar($user->email, 80) }}" alt="{{ $user->name }}">
Backed by a small helper that md5s the normalized email. That's the whole feature — no dependency required.
Where to look first: the bundle's GravatarHelper/Twig extension (it documents the parameter semantics well), then the Gravatar docs for the URL format. Skip the Symfony DI configuration entirely; it doesn't map to Laravel.
The bundle is dead weight in Laravel, so what's worth borrowing is its API shape, not its code.
Service + Blade directive. Bind a singleton exposing avatar(string $email, int $size = 80, string $default = 'mp', string $rating = 'g'): string. Register either a Blade directive (@gravatar($email, 80)) or an <x-avatar> component.
Model accessor. Put it on User where 90% of usage lives:
public function getAvatarUrlAttribute(): string
{
return app(Gravatar::class)->avatar($this->email, 96);
}
Then $user->avatar_url works in views, API resources, and mail templates uniformly.
Config. Translate the Symfony YAML (size, default, rating, force_default) into config/gravatar.php and read via config('gravatar.default'). This keeps the same knobs without the Symfony config loader.
Caching. Gravatar serves avatars with long CDN cache headers — render the URL directly and let the browser/CDN absorb the work. Cache the URL string (cheap) if you're building large lists; do not proxy images through your app unless you need privacy (see Gotchas). md5 is deterministic, so cache()->remember('avatar:'.md5($email), ...) only pays off when resolving a proxied default image.
Integration tip: Keep email normalization in exactly one place. If you allow avatar changes later, you want one function to audit, not five call sites.
Testing. Assert URL shape, not exact strings. A single unit test on normalization (" [email protected] " → correct hash) catches nearly every real-world bug.
hash('md5', trim(strtolower($email))). A stray space or uppercase letter yields a broken avatar with no error — just a generic default.https://www.gravatar.com/avatar/ or https://secure.gravatar.com/avatar/. Plain HTTP triggers mixed-content warnings.d= defaults are limited (mp, identicon, monsterid, wavatar, retro, robohash, blank). For a custom fallback, URL-encode it: 'd=' . urlencode($url). Add f=y to force the default even when the user has a Gravatar.g, pg, r, x — passing a lower rating than the user's setting silently downgrades. Default to g and don't expect r to show explicit content.composer require it anyway: there is no service provider, Twig's gravatar() syntax is meaningless in Blade, and the bundle expects Symfony's container and config loader. You'll write adapters for both — at which point you've written the package.AvatarProvider interface now. Swapping providers later is much harder once gravatar() is sprinkled across views.d= URL. Verify md5(strtolower(trim($email))) against Gravatar's own examples before blaming anything else.How can I help you explore Laravel packages today?