承接 danjamesmills/initials-avatar-generator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

danjamesmills/initials-avatar-generator

Composer 安装命令:

composer require danjamesmills/initials-avatar-generator

包简介

README 文档

README

Latest Version on Packagist Total Downloads GitHub Actions

Introducing the Laravel Avatar package, a powerful tool for generating unique avatar images for any model in your Laravel application. This package allows you to easily create unique avatar images based on fields you specify for your models, such as name, email, or any other field. With this package, you can easily add avatar functionality to your application and ensure that each user or model has a distinct and personalised avatar image. It's also configurable to use different image generation libraries, so you can pick the one that fits your project best. With a simple and intuitive API, you can easily generate avatars for any model in your application, saving you time and effort. The Laravel Avatar package makes it easy to add personalized avatars to your application, enhance the user experience and make your app look more professional.

Installation

You can install the package via composer:

composer require danjamesmills/initials-avatar-generator

Publish Config (optional)

You should publish the migration and the config/initials-avatar-generator.php config file with:

php artisan vendor:publish --provider="DanJamesMills\InitialsAvatarGenerator\InitialsAvatarGeneratorServiceProvider"

Run the migrations: After the config and migration have been published and configured, you can create the tables for this package by running:

php artisan migrate

Publicly Accessible Storage Path

In the config/initials-avatar-generator.php we have used the following path below for storage of avatar images, feel free to change this.

'storage_path' => storage_path('app/public/avatars/'),

If your using the above don't forget to link storage and public paths from console and create 'avatars' folder.

mkdir storage/app/public/avatars
php artisan storage:link

Basic Usage

First, add the DanJamesMills\InitialsAvatarGenerator\Traits\HasAvatar trait to your User model(s):

use Illuminate\Foundation\Auth\User as Authenticatable;
use DanJamesMills\InitialsAvatarGenerator\Traits\HasAvatar;

class User extends Authenticatable
{
    use HasAvatar;

    // ...
}

Defining An Accessor

use Illuminate\Foundation\Auth\User as Authenticatable;
use DanJamesMills\InitialsAvatarGenerator\Traits\HasAvatar;
use Illuminate\Database\Eloquent\Casts\Attribute;

class User extends Authenticatable
{
    /**
     * Get the user's avatar.
     *
     * @return \Illuminate\Database\Eloquent\Casts\Attribute
     */
    protected function avatar(): Attribute
    {
        return Attribute::make(
            get: fn ($value) => url("/storage/avatars/{$value}"),
        );
    }
}

Define Model Avatar Fields

use Illuminate\Foundation\Auth\User as Authenticatable;
use DanJamesMills\InitialsAvatarGenerator\Traits\HasAvatar;

class User extends Authenticatable
{
    /**
     * Used to define the fields of which initials avatar 
     * generator will create initials from.
     *
     * @return string
     */
    protected function defineNameInitialsAvatarGenerator(): string
    {
        return $this->name;
    }
}

If you have used a different column name from the default migration name of 'avatar', you must define this new column name on the model.

use Illuminate\Foundation\Auth\User as Authenticatable;
use DanJamesMills\InitialsAvatarGenerator\Traits\HasAvatar;

class User extends Authenticatable
{
    /**
     * Used to define the column field name of which 
     * you want to save avatar image to.
     *
     * @return string
     */
    protected function defineAvatarColumnName(): string
    {
        return 'avatarColumnName';
    }
}

Generating Avatar

If your model has no avatar set, you can generate one below.

$user = User::findOrFail(4);

$user->generateAvatarAndSet();
$user->save();

return "<img src='{$user->avatar}' width='250px' />";

If you update the value of the avatar field i.e user's name, an avatar will be automatically generated and saved for you.

$user = User::findOrFail(4);

$user->name = 'John Doe'; // changed from Dan Doe
$user->save();

return "<img src='{$user->avatar}' width='250px' />";

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email daniel620@hotmail.co.uk instead of using the issue tracker.

Credits

License

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

danjamesmills/initials-avatar-generator 适用场景与选型建议

danjamesmills/initials-avatar-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「danjamesmills」 「initials-avatar-generator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 danjamesmills/initials-avatar-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 danjamesmills/initials-avatar-generator 我们能提供哪些服务?
定制开发 / 二次开发

基于 danjamesmills/initials-avatar-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 41
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-10