gridprinciples / laravel-placeholder-avatars
Serve SVG avatars from your Laravel application
Fund package maintenance!
Grid Principles
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
Requires (Dev)
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2024-12-09 07:25:31 UTC
README
This package gets you several BoringAvatar designs rendered in your Laravel application as SVGs. They can be rendered via configurable URL or by direct usage of a Blade component.
Installation
You can install the package via composer:
composer require gridprinciples/laravel-placeholder-avatars
Usage
Via URL
If you plan on rendering via URL, you must register it in your routes file:
// routes/web.php use GridPrinciples\PlaceholderAvatars\Facades\PlaceholderAvatars; PlaceholderAvatars::route('avatar.svg', type: 'beam');
By default, you can use query parameters to set the generation options. For example:
/avatar.svg?name=JohnDoe&square=1
...would generate the same face every time ("JohnDoe" as the seed) in a square format.
If you want to dictate which options are used in generation, you can supply these options when adding the route:
// routes/web.php use GridPrinciples\PlaceholderAvatars\Facades\PlaceholderAvatars; PlaceholderAvatars::route('face.svg', // which design should render (optional; defaults to "beam") type: 'marble', // enforce a red color scheme colors: ['#440000', '#110000', '#CC0000'], // force a circular avatar, a square will never be produced even if requested square: false, // we are rendering an SVG so this doesn't matter much, but you can set the size size: 256, );
Via component
You can also render the SVGs inline within any Blade component:
<x-placeholder-avatar::marble :name="$user->uuid" class="rounded-lg" square />
Avatars
The following types from BoringAvatars are currently supported:
beam
marble
pixel
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- BoringDesigners - for making some really good open-source avatars
- Spatie - for a great package skeleton
- Greg Brock
- All Contributors
License
The MIT License (MIT). Please see License File for more information.