drago-ex / gravatar
Simple and customizable Gravatar integration for PHP applications, allowing easy Gravatar image generation based on user email with options for size, default image, and rating.
Requires
- php: >=8.3 <9
- nette/di: ^3.2
- nette/utils: ^4.0
Requires (Dev)
- nette/bootstrap: ^3.2
- nette/tester: ^2.5
- phpstan/phpstan-nette: ^1.2.9
- tracy/tracy: ^2.10
README
Simple and customizable Gravatar integration for PHP applications.
Requirements
- PHP >= 8.3
- Nette Framework
- Composer
Installation
composer require drago-ex/gravatar
Extension Registration
After installation, register the extension in your Nette configuration (neon file):
extensions: gravatar: Drago\Gravatar\DI\GravatarExtension
Optional configuration
gravatar: size: 80 defaultImage: "mm" rating: "g"
You can adjust the size, defaultImage, and rating parameters based on your needs.
Examples
Once the extension is registered, you can use the Gravatar functionality in your presenters and templates.
Overview
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.
Features
- 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.
Using Gravatar in Presenters
Add the GravatarAdapter trait to your presenter:
use Drago\Gravatar\GravatarAdapter; protected function beforeRender(): void { parent::beforeRender(); $gravatar = $this->gravatar; $gravatar->setEmail('someone@somewhere.com'); $this->template->gravatar = $this->gravatar->getGravatar(); }
In Template
In your Latte template, simply output the Gravatar image by using the URL provided by the presenter:
<img src="{$gravatar}" alt="">
Customizing Gravatar
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.