Component to search and obtain images registered in the Gravatar service.
- PHP >= 7.4;
- Composer.
To run the component tests, run the command below.
composer tests
The command below will run PHPStan level 4 analysis.
composer code-analysis
composer require diego-brocanelli/image-gravatar-php dev-master
<?php
require_once __DIR__.'/vendor/autoload.php';
use DiegoBrocanelli\Gravatar\Gravatar;
$email = 'hackershousebr@gmail.com';
$gravatar = new Gravatar($email);
$url = $gravatar->buildURL(); // return: https://www.gravatar.com/avatar/dfeea822891ef9e6df82ec9f4a74cf8d?s=80&d=mm&r=g
<?php
require_once __DIR__.'/vendor/autoload.php';
use DiegoBrocanelli\Gravatar\Gravatar;
$email = 'hackershousebr@gmail.com';
$gravatar = new Gravatar($email);
$image = $gravatar->buildImage(); // return: <img src='https://www.gravatar.com/avatar/dfeea822891ef9e6df82ec9f4a74cf8d?s=80&d=mm&r=g'/>
It can be used between 1px - 2048px, by default used 80px;
<?php
require_once __DIR__.'/vendor/autoload.php';
use DiegoBrocanelli\Gravatar\Gravatar;
$email = 'hackershousebr@gmail.com';
$gravatar = new Gravatar($email);
$gravatar->setImageSize(200); // return image 200px
The following options are available [404 | mm | identicon | monsterid | wavatar] 'mm' is used by default.
<?php
require_once __DIR__.'/vendor/autoload.php';
use DiegoBrocanelli\Gravatar\Gravatar;
$email = 'hackershousebr@gmail.com';
$gravatar = new Gravatar($email);
$gravatar->setImageSet('wavatar');
We have the following options available [g | pg | r | x] 'g' is used by default.
<?php
require_once __DIR__.'/vendor/autoload.php';
use DiegoBrocanelli\Gravatar\Gravatar;
$email = 'hackershousebr@gmail.com';
$gravatar = new Gravatar($email);
$gravatar->setMaxRating('pg');
We can include attributes in our image, thus facilitating its use, in the example below the CSS class 'image-gravatar' is inserted
<?php
require_once __DIR__.'/vendor/autoload.php';
use DiegoBrocanelli\Gravatar\Gravatar;
$email = 'hackershousebr@gmail.com';
$gravatar = new Gravatar($email);
$gravatar->setImageOptions(array('class' => 'image-gravatar'));
$gravatar->buildImage(); // return: <img src='https://www.gravatar.com/avatar/dfeea822891ef9e6df82ec9f4a74cf8d?s=80&d=mm&r=g' class="image-gravatar"/>