mmnijas/avatar
Composer 安装命令:
composer require mmnijas/avatar
包简介
Avatar Generator is a lightweight PHP package designed to generate avatars based on user names. It offers two flexible modes for avatar generation, letter based avatar and random image avatar
README 文档
README
Here’s a complete README.md file with all the content grouped together:
# Avatar Generator A simple and customizable avatar generator for PHP that creates PNG images based on user initials. This package uses the Intervention Image library for image manipulation. ## Features - Generates avatar images with user initials. - Customizable image size, background color, and text color. - Uses random dark shades for backgrounds. - Supports single and double initials. ## Installation To install the Avatar Generator package, you can include it in your `composer.json` or run the following command: ```bash composer require mmnijas/avatar ```
Requirements
- PHP 7.2 or higher
- Intervention Image library
You can install the Intervention Image library via Composer:
composer require intervention/image
Usage
Route Definition
First, you need to define a route for generating avatars in your web.php file:
Route::get('/avatar', [AvatarController::class, 'generateAvatar'])->name('avatar');
Controller Function
In your controller (e.g., AvatarController), add the following function:
use Mmnijas\Avatar\Generate; use Illuminate\Http\Request; public function generateAvatar(Request $request) { return Generate::avatar($request->all()); }
Displaying the Avatar
You can generate and display an avatar image in your Blade view using the following code:
<img src="{{ route('avatar', ['name' => 'Nijas M M', 'size' => 200]) }}" alt="Avatar" />
Customization Options
You can customize the avatar by passing additional parameters:
- name: The full name from which initials will be extracted (default is "John Doe").
- size: The size of the avatar image in pixels (default is 200).
- bg: Background color in hexadecimal format (optional).
- color: Text color in hexadecimal format (optional).
Example with Customization
<img src="{{ route('avatar', ['name' => 'Nijas M M', 'size' => 200, 'bg' => '#3498db', 'color' => '#ffffff']) }}" alt="Avatar" />
Example Code
Here’s a complete example of how to set everything up:
-
Define Route in
web.php:Route::get('/avatar', [AvatarController::class, 'generateAvatar'])->name('avatar');
-
Controller Function in
AvatarController:use Mmnijas\Avatar\Generate; use Illuminate\Http\Request; public function generateAvatar(Request $request) { return Generate::avatar($request->all()); }
-
Display Avatar in your Blade view:
<img src="{{ route('avatar', ['name' => 'John Doe', 'size' => 150]) }}" alt="Avatar" />
<img src="{{ route('avatar', [ 'name' => 'Nijas M M', 'size' => 200, 'bg' => '#3498db', 'color' => '#ffffff' ]) }}" alt="Avatar" />
License
This package is open-source software licensed under the MIT License.
Contributing
If you would like to contribute to this package, feel free to submit a pull request or open an issue.
Acknowledgments
Thanks to the Intervention Image library for providing the tools to manipulate images easily.
composer require mmnijas/avatar
use App\Http\Controllers\TestController;
Route::get('/avatar', [TestController::class, 'generateAvatar'])->name('avatar');
mmnijas/avatar 适用场景与选型建议
mmnijas/avatar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 09 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mmnijas/avatar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mmnijas/avatar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 34
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-19