PHP code example of forxer / gravatar

1. Go to this page and download the library: Download forxer/gravatar library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

forxer / gravatar example snippets


use Gravatar\Gravatar;
use Gravatar\Enum\DefaultImage;
use Gravatar\Enum\Extension;

$avatar = Gravatar::image('[email protected]')
    ->size(120)
    ->defaultImage(DefaultImage::ROBOHASH)
    ->extension(Extension::JPG);
//...
echo $avatar;

use Gravatar\Gravatar;

// Get a Gravatar image URL
echo Gravatar::image('[email protected]');
// output: https://www.gravatar.com/avatar/5658ffccee7f0ebfda2b226238b1eb6e

// With parameters
$avatar = Gravatar::image('[email protected]')
    ->size(120)
    ->ratingPg()
    ->extensionWebp()
    ->defaultImageRobohash();
echo $avatar;

// Get a Gravatar profile URL
echo Gravatar::profile('[email protected]')->formatJson();

use Gravatar\Enum\Rating;
use Gravatar\Enum\Extension;
use Gravatar\Enum\DefaultImage;

$image->maxRating(Rating::PG)
    ->extension(Extension::WEBP)
    ->defaultImage(DefaultImage::ROBOHASH);

$image->ratingPg()
    ->extensionWebp()
    ->defaultImageRobohash();

// Using helpers (define your own)
$avatar = gravatar('[email protected]')->size(120);

// Using static methods
$avatar = Gravatar::image('[email protected]')->size(120);

// Direct instantiation
$avatar = new Image('[email protected]');
$avatar->size(120);