2017 © Pedro Peláez
 

library avatarer

Avatarer - Social media avatars for Laravel 5

image

artdarek/avatarer

Avatarer - Social media avatars for Laravel 5

  • Tuesday, February 21, 2017
  • by Artdarek
  • Repository
  • 1 Watchers
  • 8 Stars
  • 202 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 20 % Grown

The README.md

Avatarer - Social media avatars for Laravel 5

Easy get avatars from social services like Facebook.com and Gravatar.com - initially package was build for Laravel 5 but it can work as standalone library too., (*1)


Supported Providers

A Provider can be a social network service that allows to get it's users avatars. As for right now we support:, (*2)

  • Gravatar
  • Facebook
  • Twitter

Installation

Via composer require command

Use composer require command to install this package., (*3)

``` bash $ composer require artdarek/avatarer, (*4)


#### Adding package to composer.json file manually Add package to your composer.json file:

"require": { "artdarek/avatarer": "2.0.*" }, (*5)


Use [composer](http://getcomposer.org) update command to install this package. ``` bash $ composer update

Registering the Package

Add the Avatarer alias into your config file config/app.php:, (*6)

'aliases' => [
    'Avatarer' => Artdarek\Avatarer\Support\Laravel\Facades\Avatarer::class,
],

Usage

Initialize

To ininitialize Avatarer call make() method and pass Provider name (service name like Gravatar/Facebook/Twitter):, (*7)




If you want to use Avatarer library outside of Laravel framework or you don't want to use Avatarer Facade in your Laravel application, you can do this:, (*8)

make(Gravatar::class);
?>

or, (*9)

make(Gravatar::class);
?>

or, (*10)

make(Gravatar::class);
?>

Setting a user

Generating avatar with default settings is very simple and all you have to do is to call user() method with user id as a parameter (each Provider can identify user differently via email/id/screenname etc.):, (*11)

For Gravatar we use Email:, (*12)

user( $email );

    // get url
    $url = $avatar->get();

?>

For Facebook we use UserID:, (*13)

user( $userID );

    // get url
    $url = $avatar->get();
?>

For Twitter we use user ScreenName:, (*14)

user( $userScreenName );

    // get url
    $url = $avatar->get();
?>

Setting avatar size

If you want to set a size of avatar that should be returned you can use size() method. This method can take two parameters width and height and both are optional (notice that not all providers will require or use both width and height, for example Gravatar expects only width)., (*15)

For Gravatar:, (*16)

user( $email );
    $avatar->size( 200 );

    // get url
    $url = $avatar->get();
?>

For Facebook:, (*17)

user( $userID );
    $avatar->size( 200, 200 );

    // get url
    $url = $avatar->get();
?>

Setting provider-specific options

If you want to customize avatar a little bit more you can set some additional parameters using options() method., (*18)

For Gravatar:, (*19)

user( $email );
    $avatar->size( 200 );
    $avatar->options([
        'default' => 'mm', // Url to your default avatar image or [ 404 | mm | identicon | monsterid | wavatar | blank | retro ]
        'forceDefault' => null, // If for some reason you wanted to force the default image to always load [ y ]
        'ratings' => 'g', // Maximum rating (inclusive) [ g | pg | r | x ]
    ]);

    // get url
    $url = $avatar->get();
?>

For Facebook:, (*20)

<?php
    $avatar = Avatarer::make(Facebook::class);
    $avatar->user( $userID );
    $avatar->size( 200, 200 );
    $avatar->options([
        'type' => 'square', // Type of avatar [ small, normal, album, large, square ]
    ]);
    $url = $avatar->get();
?>

Methods chaining

If thats more convinient for you you can chain all methods like below:, (*21)

<?php
    $url = Avatarer::make(Gravatar::class)
        ->user( $email )
        ->size(220)
        ->options([
            'default' => 'mm'
            'ratings' => 'g'
        ])->get();
?>

Output Formating

Default string output

With Avatarer by using get() method you can get url string of user avatar:, (*22)

<?php
    $avatar = Avatarer::make(Gravatar::class)->user( $email )->size('200');
    $url = $avatar->get();
?>

Changing output format

If you wish to get output in different format like Array, Json or even HTML code you can do that by calling get() method with Output object that implements OutputInterface as a parameter:, (*23)

To get Array (add use \Artdarek\Avatarer\Output\ToArray; at the top of your class):, (*24)

user( $email )->size('200');
    $url = $avatar->get(new ToArray);
?>

To get JSON (add use \Artdarek\Avatarer\Output\ToJson; at the top of your class):, (*25)

user( $email )->size('200');
    $url = $avatar->get(new ToJson);
?>

To get Object (add use \Artdarek\Avatarer\Output\ToObject; at the top of your class):, (*26)

user( $email )->size('200');
    $url = $avatar->get(new ToObject);
?>

To get HTML (add use \Artdarek\Avatarer\Output\ToHtml; at the top of your class):, (*27)

user( $email )->size('200');
    $url = $avatar->get(new ToHtml);
?>

If you want to have more controll over returned HTML code you can pass array with additional attributes via ToHtml() constructor, for examle:, (*28)

user( $email )->size('200');
    $url = $avatar->get(
        new ToHtml([
            'class' => 'avatar',
            'id' => 'user123' 
        ])
    );
?>

The Versions

21/02 2017

dev-master

9999999-dev https://github.com/artdarek/avatarer

Avatarer - Social media avatars for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel 5 avatar gravatar avatarer

21/02 2017

v2.x-dev

2.9999999.9999999.9999999-dev https://github.com/artdarek/avatarer

Avatarer - Social media avatars for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel 5 avatar gravatar avatarer

21/02 2017

2.0.2

2.0.2.0 https://github.com/artdarek/avatarer

Avatarer - Social media avatars for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel 5 avatar gravatar avatarer

20/02 2017

2.0.1

2.0.1.0 https://github.com/artdarek/avatarer

Avatarer - Social media avatars for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel 5 avatar gravatar avatarer

20/02 2017

v1.x-dev

1.9999999.9999999.9999999-dev https://github.com/artdarek/avatarer

Avatarer - Social media avatars for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel 5 avatar gravatar avatarer

20/02 2017

1.0.2

1.0.2.0 https://github.com/artdarek/avatarer

Avatarer - Social media avatars for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel 5 avatar gravatar avatarer

20/02 2017

2.0.0

2.0.0.0 https://github.com/artdarek/avatarer

Avatarer - Social media avatars for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel 5 avatar gravatar avatarer

07/05 2016

1.0.1

1.0.1.0 https://github.com/artdarek/avatarer

Avatarer - Social media avatars for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel 5 avatar gravatar avatarer

23/09 2015

1.0.0

1.0.0.0 https://github.com/artdarek/avatarer

Avatarer - Social media avatars for Laravel 5

  Sources   Download

MIT

The Requires

 

laravel 5 avatar gravatar avatarer