sh-sabbir/faker-php-avatar

A provider for FakerPHP/Faker to generate Avatar Based on DiceBear

dev-master 2022-02-24 07:07 UTC

This package is auto-updated.

Last update: 2024-12-24 13:30:35 UTC


README

Social card of FakerPHP-Avatar

FakerPHP Avatar

Packagist Downloads GitHub file size in bytes GitHub

FakerPHP Avatar is an addon package for Faker to generate fake avatars based on DiceBear. It Supports all 22 styles of DiceBear.

Getting Started

Installation

FakerPHP Avatar requires Faker >= 1.0.

composer require sh-sabbir/faker-php-avatar

Documentation

Full documentation can be found over on sh-sabbir.github.io/FakerPHP-Avatar.

Basic Usage

Add Provider

$faker = Faker\Factory::create();
$faker->addProvider(new Sabbir\Faker\AvatarProvider($faker));

Default settings

$faker->avatarUrl($style = "adventurer", $size = null, $slug = null, $bg = null, $scale = null, $flip = null);

Generate Avatar URL

$url = $faker->avatarUrl();  
// https://avatars.dicebear.com/api/adventurer/:seed.svg

$url = $faker->avatarUrl('male');  
// https://avatars.dicebear.com/api/male/:seed.svg

$url = $faker->avatarUrl('male',100);  
// https://avatars.dicebear.com/api/adventurer/:seed.svg?size=100

$url = $faker->avatarUrl('male',100,'my-custom-slug');  
// https://avatars.dicebear.com/api/adventurer/my-custom-slug.svg?size=100

$url = $faker->avatarUrl('male',100,'my-custom-slug','#cfcfcf');  
// https://avatars.dicebear.com/api/adventurer/my-custom-slug.svg?b=%23cfcfcf&size=100

$url = $faker->avatarUrl('male',100,'my-custom-slug','#cfcfcf',100);  
// https://avatars.dicebear.com/api/adventurer/my-custom-slug.svg?size=100&b=%23cfcfcf&scale=100

$url = $faker->avatarUrl('male',100,'my-custom-slug','#cfcfcf',100,1);  
// https://avatars.dicebear.com/api/adventurer/my-custom-slug.svg?size=100&b=%23cfcfcf&scale=100&flip=1

Check documentation for more complex example.

Available Styles

All Settings and Default Values

License

Faker is released under the MIT License. See LICENSE for details.