2017 © Pedro Peláez
 

library gravatar

Avatar Generator

image

artlabs/gravatar

Avatar Generator

  • Tuesday, October 6, 2015
  • by shandy05
  • Repository
  • 2 Watchers
  • 0 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

# gravatar

Installation

Add Gravatar to your composer.json file:, (*1)

composer require artlabs/gravatar

Use composer to install this package., (*2)

$ composer update

Registering the Package

Add the Gravatar Service Provider to your config in config/app.php:, (*3)

'providers' => array(
    Artlabs\Gravatar\GravatarServiceProvider::class
),

Usage

Generating gravatar url by user() method

Generating avatar with default settings is very simple and all you have to do is to call user() method with user email as a paramterer:, (*4)

url();

?>

If you want to customize avatar a little bit you can set some more parameters using additional methods like size(), rating(), defaultImage()., (*5)

size('220');

    // Maximum rating (inclusive) [ g | pg | r | x ]
    // defaults to 'g'
    $gravatar->rating('g');

    // Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
    // You can also specify url to your own default avatar image
    // defaults to 'mm'
    $gravatar->defaultImage('mm');

    // set Gravatar to build urls with https [true = use https, false = ise http]
    // defaults to 'false'
    $gravatar->secured( true );

    // get gravatar url as a string
    $url = $gravatar->url();

?>

U can also chain all methods:, (*6)

<?php
    $url = Gravatar::user( $email )->size('220')->rating('g')->defaultImage('mm')->url();
?>

Generating gravatar url by make() method

Basic way to generate gravatar url is just to call make() method with user email address as a parameter (all other parameters will be loaded from defaults)., (*7)

url();

?>

U can aslo chain methods:, (*8)

<?php
    // to get url string
    $url = Gravatar::make( $email )->url();
?>

If you want specify size of avatar or some other additional parameters you can do this by passing array with parameters to make() method:, (*9)

 $email, 'size' => 220] )->url();

    // create a gravatar object with some other additional parameters
    $url = Gravatar::make( [
        'email' => $email,
        'size' => 220,
        'defaultImage' => 'mm',
        'rating' => 'g',
        'secured' => true
    ])->url();
?>

Generating HTM avatar code

With Gravatar you can get url string of user avatar by calling url() method but also you can generate full html code by calling html() method instead of url()., (*10)

size('120');

     // get gravatar  html code
    $html = $gravatar->html();
?>

If you want to have more controll over the returned html code you can pass some additional html attributes to html() method, for examle:, (*11)

<?php
    $html = Gravatar::user( $email )->html( ['class' => 'avatar', 'id' => 'user123' ] );
?>

The Versions

06/10 2015

dev-master

9999999-dev

Avatar Generator

  Sources   Download

MIT

The Requires