rackbeat/laravel-ui-avatars
Composer 安装命令:
composer require rackbeat/laravel-ui-avatars
包简介
Official Laravel wrapper around ui-avatars.com and LasseRafn/php-initial-avatar-generator
README 文档
README
Installation
You just require using composer and you're good to go!
composer require rackbeat/laravel-ui-avatars
The Service Provider is automatically registered.
Setup
To setup the config file, you publish it like so:
php artisan vendor:publish --provider="Rackbeat\UIAvatars\UIAvatarsServiceProvider"
You can edit the file in config/ui-avatars.php.
Usage
1. Add the Rackbeat\UIAvatars\HasAvatar trait to your Model (e.g. App\Users)
// ... class User extends Authenticatable { use \Rackbeat\UIAvatars\HasAvatar; // ... }
2. Create a new method on your Model.
This method is practically a proxy to call the HasAvatar methods. It will return a gravatar from the e-mail, with a fallback to the avatar using ui-avatars.com API.
public function getAvatar( $size = 64 ) { return $this->getGravatar( $this->email, $size ); }
NOTICE: Gravatar is only available using the API, not locally generated avatars.
3. (Optional) Re-define the name field
Assuming you're not using the default User Model in Laravel, you can override which field is being used for the name.
public function getAvatarNameKey( ) { return 'full_name'; }
Available methods
getInitials($length=null)
Returns the generated initials, from the name, used in the avatar.
Default $length can be defined in config/ui-avatars.php (length key)
getUrlfriendlyAvatar($size=null)
Return a urlfriendly formatted avatar (URL or base64).
Example usage:
<img src="{{ $user->getUrlfriendlyAvatar() }}" />
Default $size can be defined in config/ui-avatars.php (image_size key)
getAvatarBase64($size=null)
Return a base64 representation of the avatar.
Default $size can be defined in config/ui-avatars.php (image_size key)
getAvatarImage($size=null)
Return a Image object of the avatar.
Default $size can be defined in config/ui-avatars.php (image_size key)
getGravatar($email, $size=null)
Return a link to a Gravatar image using the specified email, and a fallback to using our own generator (assuming provider = api)
Default $size can be defined in config/ui-avatars.php (image_size key)
Available options
In the config file you can specify different options.
| Key | Description | Default | Available Options / Type |
|---|---|---|---|
| provider | Which provider to use for generating avatars. | api |
local or api |
| length | Max initials length (amount of letters) | 2 |
Number, min: 1, max: unlimited |
| image_size | Default width & height for the generated avatar. | 48 |
Number, min: 1, max: unlimited (512 using api provider) |
| font_size | Font size in percentage of image_size. |
0.5 |
Number, min: 0, max: 1 |
| rounded | Should the generated avatar be a rounded circle? (its recommended to disable and round using CSS) | false |
Boolean |
| smooth_rounding | If rounded is enabled, and provider is local, you can enable smoother rounding with the cost of performance. |
true |
Boolean |
| uppercase | Should the initials be forced uppercase or not. | true |
Boolean |
| background_color | Default HEX background color for avatars. | #a0a0a0 |
Hex |
| font_color | Default HEX font color for avatars. | #222 |
Hex |
| providers | List of available providers. For you to add your own provider. | Array of providers |
Requirements
- PHP >= 7.1
rackbeat/laravel-ui-avatars 适用场景与选型建议
rackbeat/laravel-ui-avatars 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 148.46k 次下载、GitHub Stars 达 43, 最近一次更新时间为 2018 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「avatars」 「Initials」 「ui-avatars」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rackbeat/laravel-ui-avatars 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rackbeat/laravel-ui-avatars 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rackbeat/laravel-ui-avatars 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
User Avatar manager dependency for Laravel Enso
User Avatar manager dependency for Laravel Liberu
PHP SVG avatar generator based on https://github.com/fangpenlin/avataaars-generator
User Avatar manager dependency for Laravel Enso
Additional Plug & Play Avatars for your Nova Panel.
AvatarIo api wrapper
统计信息
- 总下载量: 148.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 43
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-03