gridprinciples/laravel-placeholder-avatars

Serve SVG avatars from your Laravel application

v0.2.0 2024-10-16 04:04 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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

License

The MIT License (MIT). Please see License File for more information.