Skip to content

A simple package to help you generate avatars for your users using dice bear

License

Notifications You must be signed in to change notification settings

RichardJesse/diceBearPhp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dice Bear Image

Packagist Downloads PHP Version Current Version

Dice Bear for Php

This is a simple package that is aimed at making getting avatars from Dice Bear easy in your php application.No official affiliation with the original dice bear

Installation

To install the package all you need to do is run this command in your terminal.(assuming that you have composer installed)

 composer require jesse-richard/dice-bear-php

How to use

Using diceBearPhp is pretty easy all you need to do is make use of the NeedsAvatar Trait and you'll be good to go.

use JesseRichard\DiceBearPhp\Trait\NeedsAvatar;

class User {
    use NeedsAvatar;
}

Utilities

This package provides some utilities to make the experience with the dice Bear easy.

Styles

Dice Bear offers a couple of styles that you can take advantage of and the package supports all the available styles. This package provides for three ways to make use of the Dice Bear Styles. You can have a look at all the styles here

// say the NeedsAvatar Trait is in use in the user class

$user = new User();

// You may choose to get a random style using the randomStyle() method like so
$user->randomStyle()

//You may choose to pass the style directly by name
$user->style('thumbs')

// You may choose to use the style as a method and optionally pass in the format you want it to be in using camelCase eg(big ears Neutral)
$user->bigEarsNeutral('svg')

// or 
$user->bigEarsNeutral()

Format

The avatars that are provided by the Dice Bear Api are in different file formats. The package provides a method to allow you to get the file in the format that you find most convinient. Supported format

// getting the avatar in jpeg format
$user->format('jpeg')

// The alternative way of passing the format is while using the stlyle as a method as had been shown
$user->bigEarsNeutral('svg')

Seed

This is the property that determines the initial value and that way you are able to create the same avatar again and again.And its simple to use.

// You may pass in your unique value that you would like to be used could be anything but you must pass it as a string
$user->seed('name')->randomStyle();

Flip

This property determines whether the image that is produced is fliped or not.

// you may not pass a parameter the default value is true
$user->flip()
 //  OR
// You may choose to pass a parameter
$user->flip(false)

Rotate

This property allows you to choose how much you would like to rotate the image around a 360 degree angle.

// Rotates the image that is produced by 60 degrees
$user->rotate(60)

Scale

This property determines how zoomed in or scaled the image that is produced will be.The range being between 0 to 200

// Scales the image by factor of 100
$user->scale(100);

Radius

This property determines how rounded the image that is produced will be. The range is between 0 to 50.

// sets the radius of the image that will be produced with a radius of 40
$user->radius(40);

Translate

This property allows you to determined the position of the subject of the image that will be produced. It ranges between -100 to 100

// Translates the image that is produced by a factor of -50 on the x axis
$user->translate('X', -50);

// Translates the image that is produced by a factor of -50 on the y axis
$user->translate('Y', -50);

Background

This feature allows you to make changes to the background of the image that is produced. For the background you could change the color, type and rotation.

// Changing background color 
$user->backgroundColor('red')

// changing the background type
$user->backgroundType('solid')

// changing the angle rotation of the background 
$user->backgroundRotation(70)

Style specific options

DiceBear offers additional options that are sometimes style specific.To take advantage of this we make use of the options method.

// Say you want to make use of the Micah style and you want to customize the eyes option to be set to round
$user->style('micah')->options(['eyes' => 'round']);

Avatar alternatives

The avatars that are provided by Dice Bear are essentially image files. The package gives you the autonomy to choose what to do with them.

// You may choose to get the image content and maybe do something with it
$user->getContent()


// You may choose to save the image locally and extract the path of the image
$user->saveImage('path/to/avatars_folders')->savedPath()


// You may only be intrested in the Url of the image
$user->url()

Contributions

Contributions are highly welcomed. Feel free to fork the repo, play around to make it better.In case of any issues feel free to open an issue and i'll be right to it.A star wouldn't hurt.😉

About

A simple package to help you generate avatars for your users using dice bear

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages