PHP code example of uibar / gravatar

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

    

uibar / gravatar example snippets


    composer 

    'providers' => [
        'Uibar\Gravatar\GravatarServiceProvider',
    

    'aliases' => [
        'Gravatar' => 'Uibar\Gravatar\Facades\Gravatar',
    

$gravatar_url = Gravatar::make('[email protected]');

// We can directly specify some HTML tags as the second parameter of the
// make() method like this:
{!! Gravatar::make('[email protected]', ['class' => 'img-circle']) !!}
// We could specify the email using Method Chaining and then passing TRUE
// to the make() method
{!! Gravatar::email('[email protected]')->make(TRUE) !!}
// Or we can pass an array as the first parameter containing the email and
// the image key as TRUE like this:
{!! Gravatar::make(['email' => Auth::user()->email, 'image' => TRUE]) !!}
// You could also use the image() method chaining if you don't want to
// specify any parameters like so:
{!! Gravatar::image()->make('[email protected]') !!}

$secure_url = Gravatar::forceSecure()->make('[email protected]');
// Or you could specify inside the make() parameter array like this:
$secure_url = Gravatar::make(['email' => '[email protected]', 'forceSecure' => TRUE]);

// The following will output a full image tag with custom size, rating and
// attributes for the img tag:
{!! Gravatar::make([
    'email' => '[email protected]',
    'size' => 40,
    'rating' => 'x',
    'image' => TRUE,
    'attributes' => ['class' => 'img-circle']
]) !!}
// The same effect could be accomplished by passing the attributes for the
// img tag as second parameter of the make method and thus not specifying the
// image key as TRUE anymore
{!! Gravatar::make([
    'email' => '[email protected]',
    'size' => 40,
    'rating' => 'x'
], ['class' => 'img-circle']) !!}
// Using the get() method
{!! Gravatar::get('[email protected]', 40, 'identicon', 'x', TRUE,
            ['class' => 'img-circle']); !!}
// The order of the elements using this way DOSE MATTER. It will not work unless
// you use it using this exact order:
$url = Gravatar::get($email, $size, $default, $rating, $image, $attributes);

// For custom URLs:
$custom_url = Gravatar::email('[email protected]')->size(40)
    ->defaults('identicon')->rating('x')->make();
// For custom img tag:
{!! Gravatar::email('[email protected]')->size(40)->rating('x')
    ->attributes(['class' => 'img-circle'])->make(TRUE) !!}
// Or as learned above we could do:
{!! Gravatar::size(40)->rating('x')->make('[email protected]', ['class' => 'img-circle']) !!}