black-sheep-tech / laravel-dice-bear
A simple service provider/wrapper for the DiceBear Avatars API (https://dicebear.com/).
Requires
- php: ^8.0
- laravel/framework: >=9.0 <12.0
Requires (Dev)
- laravel/pint: ^1.17
This package is not auto-updated.
Last update: 2024-10-31 00:51:42 UTC
README
Laravel DiceBear is a PHP library for Laravel used to generate avatar using the DiceBear API (https://dicebear.com/). This package provides a simple, fluent interface for customizing avatar parameters and generating the corresponding URL. It also allows downloading and saving the avatars locally. Support for self-hosted DiceBear API is also available.
Installation
You can install the package via Composer:
composer require black-sheep-tech/laravel-dice-bear
Usage
Basic Usage (All Styles)
use BlackSheepTech\DiceBear\DiceBear; // Generates a random avatar using the 'botttsNeutral' style with a size of 128 pixels and 'Avesome Avatar Seeder' as seed. $avatarUrl = DiceBear::style('botttsNeutral')->seed('Avesome Avatar Seeder')->size(128)->getUrl(); // Alternatively, you can use the following shorthand method: $avatarUrl = DiceBear::botttsNeutral()->seed('Avesome Avatar Seeder')->size(128)->getUrl();
Download Avatar
To download the avatar directly:
// Prompts a download of the avatar to a file named 'john_doe_avatar.png', by default, if a file name is not provided, a random name will be generated. use BlackSheepTech\DiceBear\DiceBear; DiceBear::botttsNeutral()->seed('John Doe')->size(128)->download();
Save Avatar Directly to Disk
To save the avatar to a specific location:
use BlackSheepTech\DiceBear\DiceBear; // Saves the avatar to 'avatars/john_doe_avatar.png' by default. $avatarPath = DiceBear::botttsNeutral()->seed('John Doe')->size(128)->saveTo('avatars', 'john_doe_avatar'); // You can provided the disk to be used as the third parameter, by default, the application's default disk will be used. $avatarPath = DiceBear::botttsNeutral()->seed('John Doe')->size(128)->saveTo('avatars', 'john_doe_avatar', 'public');
Supported Styles
Currently, the following DiceBear styles are supported:
Style Specific Options
Most styles have options specific to them.
- BotttsNeutral - Detailed Options
- Eyes
- Mouth
- AdventurerNeutral - Detailed Options
- Eyebrows
- Eyes;
- Mouth
- Glasses
- Glasses Probability
- Initials - Does not support any additional options
Requirements
- PHP 8.0 or higher
- Laravel framework version 9.0 or higher
License
This package is open-sourced software licensed under the MIT license.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request on GitHub.