black-sheep-tech/laravel-ui-avatars
Composer 安装命令:
composer require black-sheep-tech/laravel-ui-avatars
包简介
A simple service provider/wrapper for the UI Avatars API (https://ui-avatars.com).
README 文档
README
Laravel UiAvatars is a PHP library for Laravel used to generate avatar using the UI Avatars API (https://laravel-ui-avatars.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.
Installation
You can install the package via Composer:
composer require black-sheep-tech/laravel-ui-avatars
Usage
Basic Usage / Url Generation
use BlackSheepTech\UiAvatars\UiAvatars; $avatarUrl = UiAvatars::make() ->name('John Doe') ->size(128) ->background('#ffffff') ->color('#000000')->getUrl();
With all customizations
$avatarUrl = UiAvatars::make() ->name('John Doe') ->size(128) ->background('#ffffff') ->color('#000000') ->length(2) ->rounded(true) ->bold(true) ->uppercase(true) ->format('png') ->getUrl();
Download Avatar
To download the avatar directly:
use BlackSheepTech\UiAvatars\UiAvatars; // 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. UiAvatars::make()->name('John Doe')->download('john_doe_avatar');
Save Avatar Directly to Disk
To save the avatar to a specific location:
use BlackSheepTech\UiAvatars\UiAvatars; // Saves the avatar to 'avatars/john_doe_avatar.png' by default. $avatarPath = UiAvatars::make()->name('John Doe')->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 = UiAvatars::make()->name('John Doe')->saveTo('avatars', 'john_doe_avatar', 'public');
Customization
The UiAvatarsService class allows for various customizations:
- name: Sets the name from which the initials are generated.
- background: Sets the background color (hex code or 'random')(default: random).
- color: Sets the font color (hex code)(default: 8b5d5d).
- size: Sets the size of the avatar in pixels (16 to 512)(default: 64).
- fontSize: Sets the font size ratio (0.1 to 1.0)(default: 0.5).
- length: Sets the number of characters for initials (default: 2).
- rounded: Enables rounded avatars (default: false).
- bold: Enables bold text for initials (default: false).
- uppercase: Converts initials to uppercase (default: true).
- format: Sets the format of the avatar ('png' or 'svg')(default: png).
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.
Credits
black-sheep-tech/laravel-ui-avatars 适用场景与选型建议
black-sheep-tech/laravel-ui-avatars 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 567 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 09 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 black-sheep-tech/laravel-ui-avatars 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 black-sheep-tech/laravel-ui-avatars 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 567
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-04