black-sheep-tech/laravel-dice-bear

一个简单的 DiceBear Avatars API (https://dicebear.com/) 服务提供者/包装器。

v1.0.0 2024-09-02 22:00 UTC

This package is not auto-updated.

Last update: 2024-10-03 00:31:55 UTC


README

BlackSheepTech UiAvatars

Current Version Total Downloads License Stars

Laravel DiceBear 是一个用于生成 DiceBear API (https://dicebear.com/) 的头像的 PHP 库。这个包提供了一个简单、流畅的接口来定制头像参数和生成相应的 URL。它还允许本地下载和保存头像。也支持自托管的 DiceBear API。

安装

您可以通过 Composer 安装此包

composer require black-sheep-tech/laravel-dice-bear

用法

基本用法(所有样式)

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();

下载头像

直接下载头像

// 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();

直接将头像保存到磁盘

将头像保存到指定位置

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');

支持的样式

目前支持以下 DiceBear 样式

样式特定选项

大多数样式都有特定的选项。

  • BotttsNeutral - 详细选项
    • 眼睛
    • 嘴巴
  • AdventurerNeutral - 详细选项
    • 眉毛
    • 眼睛;
    • 嘴巴
    • 眼镜
    • 眼镜概率
  • Initials - 不支持任何额外的选项

要求

  • PHP 8.0 或更高版本
  • Laravel 框架版本 9.0 或更高版本

许可证

此包是开源软件,受 MIT 许可证 许可。

贡献

欢迎贡献!请在 GitHub 上提交 Pull Request。

致谢