Skip to content
Gareth Cozens edited this page May 2, 2016 · 4 revisions

Initializing Ivatar

Using the App Container

$ivatar = App::make('Ivatar');

Using the Facade

...
use Ivatar;
...
$ivatar = Ivatar::create(['text' => 'Gareth Cozens']);

Creating, Saving, & Fetching

Create the Base Ivatar and save

$ivatar = App::make('Ivatar');
$ivatar->create([
    'text' => 'Gareth Cozens',
    'size' => 'large',
    'group' => 'author'
]);
$ivatar->save();
/* save() returns path array
*  [ 
*     'filename' => '1c585f94f29f9d5f7400bdedcce606ea.jpg', 
*     'path' => /var/www/site/public/ivatar/1c585f94f29f9d5f7400bdedcce606ea.jpg', 
*     'url' => 'http://sitename.com/ivatar/1c585f94f29f9d5f7400bdedcce606ea.jpg'
*  ]
*/

The above will output the Ivatar with a MD5 hash of the options.

We can use the fetch method to check if the configuration has been saved before and call the resource instead. If it doesn't exist it will create it and save it for us.

$ivatar = App::make('Ivatar');
$ivatar->fetch([
    'text' => 'Gareth Cozens',
    'size' => 'large',
    'group' => 'author'
]);
// returns path array. 

Response

Create a Avatar that is packaged in a Response.

$ivatar = App::make('Ivatar');
return $ivatar->serve([
    'text' => 'Gareth Cozens',
    'size' => 'large',
    'group' => 'author'
]);

Alternatively

return $ivatar->create(['text' => 'Gareth Cozens'])->response();

Formatted

Return Base64 String

$ivatar->create(['text' => 'Gareth Cozens'])->format( 'base64' );

Return img tag

$ivatar->create(['text' => 'Gareth Cozens'])->format( 'tag' );

Return img tag with full border-radius (inline-style)

$ivatar->create(['text' => 'Gareth Cozens'])->format( 'tag', 'circle' );

Return img tag with rounded corners (inline-style)

$ivatar->create(['text' => 'Gareth Cozens'])->format( 'tag', 'rounded' );