PHP code example of gravatarphp / gravatar

1. Go to this page and download the library: Download gravatarphp/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/ */

    

gravatarphp / gravatar example snippets


use Gravatar\Gravatar;

// Defaults: no default parameter, use HTTPS
$gravatar = new Gravatar([], true);

// Returns https://secure.gravatar.com/avatar/EMAIL_HASH
$gravatar->avatar('[email protected]');

// Returns https://secure.gravatar.com/avatar/EMAIL_HASH
// The fourth parameter enables validation and will prevent the
// size parameter from being added to the URL generated.
$gravatar->avatar('[email protected]', ['s' => 9001], true, true);

// Returns https://secure.gravatar.com/EMAIL_HASH
$gravatar->profile('[email protected]');

// Returns https://secure.gravatar.com/EMAIL_HASH.vcf
$gravatar->vcard('[email protected]');

// Returns https://secure.gravatar.com/EMAIL_HASH.qr
$gravatar->qrCode('[email protected]');

use Gravatar\Gravatar;

$gravatar = new Gravatar();

// Returns http://www.gravatar.com/avatar/EMAIL_HASH
$gravatar->avatar('[email protected]', [], false);

// Returns http://www.gravatar.com/EMAIL_HASH
$gravatar->profile('[email protected]', false);

// Returns http://www.gravatar.com/EMAIL_HASH.vcf
$gravatar->vcard('[email protected]', false);

// Returns http://www.gravatar.com/EMAIL_HASH.qr
$gravatar->qrCode('[email protected]', false);

use Gravatar\Gravatar;

$gravatar = new Gravatar([
    'size' => 500,
]);

// Returns https://secure.gravatar.com/avatar/EMAIL_HASH?size=500&r=g
$gravatar->avatar('[email protected]', ['r' => 'g']);