Simple and customizable Gravatar integration for PHP applications.
- PHP 8.3 or higher
- composer
composer require drago-ex/gravatar
Drago Gravatar is a simple, customizable solution for integrating Gravatar images into your PHP application. With this package, you can easily generate and display Gravatar images based on user email addresses, allowing you to customize their size, default image, and rating.
- Generate Gravatar images based on user email.
- Customizable image size (from 1 to 2048 pixels).
- Choose a default image if the user has no Gravatar.
- Set image rating (g, pg, r, x).
- Easy integration into your Nette-based application.
After installation, register the extension in your Nette configuration (neon
file):
extensions:
- Drago\User\DI\GravatarExtension(size: 80, defaultImage: 'mm', rating: 'g')
You can adjust the size, defaultImage
, and rating parameters based on your needs.
Once the extension is registered, you can use the Gravatar functionality in your presenters and templates.
In your presenter, you can access the Gravatar service, set the user's email, and pass the generated Gravatar URL to the template:
$gravatar = $this->gravatar;
$gravatar->setEmail('someone@somewhere.com');
$this->template->gravatar = $gravatar->getGravatar();
In your Latte template, simply output the Gravatar image by using the URL provided by the presenter:
<img src="{$gravatar}" alt="">
You can customize the Gravatar by changing the size, defaultImage, and rating parameters in the configuration:
size
: The size of the Gravatar image in pixels (1 to 2048). Default is 80.
defaultImage
: The default image used when the user doesn't have a Gravatar (e.g., mm
, identicon
, monsterid
, wavatar
, etc.). Default is mm
.
rating
: The rating of the Gravatar image (g
, pg
, r
, x
). Default is g.