PHP code example of jesse-richard / dice-bear-php
1. Go to this page and download the library: Download jesse-richard/dice-bear-php 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/ */
jesse-richard / dice-bear-php example snippets
use JesseRichard\DiceBearPhp\Trait\NeedsAvatar;
class User {
use NeedsAvatar;
}
// 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()
// 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')
// 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();
// you may not pass a parameter the default value is true
$user->flip()
// OR
// You may choose to pass a parameter
$user->flip(false)
// Rotates the image that is produced by 60 degrees
$user->rotate(60)
// Scales the image by factor of 100
$user->scale(100);
// sets the radius of the image that will be produced with a radius of 40
$user->radius(40);
// 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);
// Changing background color
$user->backgroundColor('red')
// changing the background type
$user->backgroundType('solid')
// changing the angle rotation of the background
$user->backgroundRotation(70)
// 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']);
// 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()