Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Gravatar Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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:

  1. Learn the Gravatar URL contract, not the bundle. The entire feature is https://www.gravatar.com/avatar/{md5(lower(trim(email)))} plus query params: s (size), d (default image), r (rating), f (force default).
  2. Skim the bundle's Gravatar service and its Twig gravatar() helper — it's a useful spec for parameter names, ordering, and defaults.
  3. Reimplement the ~30-line service in 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.

Implementation Patterns

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.

Gotchas and Tips

  • Email normalization is the #1 bug. Gravatar requires lowercase, trimmed, then md5: hash('md5', trim(strtolower($email))). A stray space or uppercase letter yields a broken avatar with no error — just a generic default.
  • HTTPS only in modern browsers. Use 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.
  • Ratings are clamped. 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.
  • Privacy / GDPR. Every avatar request sends a user identifier to gravatar.com. Consider hashing server-side with a local default, or gating Gravatar behind consent. This is a genuine reason to build the helper yourself instead of adopting a package that encourages automatic calls.
  • The Symfony↔Laravel mismatch. If you 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.
  • Archived, 2018. Last tagged release April 2018, repo archived, 0 dependents. It pins old Symfony constraints and will likely conflict with the Symfony components Laravel pulls in transitively. No security patches, no support. Treat it as a reference implementation only.
  • Extension point worth keeping. If you suspect you'll add other providers (BoringAvatar, local uploads, initials), introduce an AvatarProvider interface now. Swapping providers later is much harder once gravatar() is sprinkled across views.
  • Debugging. A broken avatar is almost always (a) hash normalization, or (b) an unencoded d= URL. Verify md5(strtolower(trim($email))) against Gravatar's own examples before blaming anything else.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package