zertex/yii2-avatar-generator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

zertex/yii2-avatar-generator

最新稳定版本:1.1.7

Composer 安装命令:

composer require zertex/yii2-avatar-generator

包简介

Avatar generator for Yii2 Framework.

README 文档

README

Generate avatar for user by his name, file or url for Yii2.

Latest Stable Version Total Downloads

Features

  • Generate avatar by username
  • Generate avatar from file or url (http only)
  • Auto select background color by username
  • Contrast color for text
  • Font face and size customize
  • Texture for background (2 available now)

Dependencies

  • PHP 7
  • PHP GD
  • zertex/avatar-generator

Installation

Install with composer:

composer require zertex/yii2-avatar-generator

or add

"zertex/yii2-avatar-generator": "*"

to the require section of your composer.json file.

Configuration

Add to common/config/main.php or config/web.php

'components' => [
    ...
    'avatar' => [
        'class' => \zertex\avatar_generator\AvatarGenerator::class,
        'images_folder' => 'path_to_image_files',
        'images_url' => 'url_to_image_files',
        'size_width' => 300,            // default: 300
        'font' => 'path_to_ttf_font',   // default: Play-Bold // may use aliases
        'font_size' => 200,             // default: 200
        'salt' => 'random_salt',        // salt for image file names
        'texture' => ['sun', 'rain'],   // texture name
        'text_over_image' => true,      // draw text over image (for avatar from file)
        'texture_over_image' => true,   // draw texture over image (for avatar from file)
    ],
],
  • images_folder - required Folder for images
  • images_url - required Url to folder with images
  • size_width - Origin image side width. Default: 300
  • font - Path to TTF font file. Yii2 aliases ready. Default: Play-Bold.ttf
  • font_size - Font size. Default: 300
  • salt - Random garbage for images file name
  • texture - Texture name: sun, rain. Default: empty
  • text_over_image - Draw text over image. For avatar created from file. Default: true
  • texture_over_image - Draw texture over image. For avatar created from file. Default: true

Using

Yii::$app->avatar->show('username', [width], [file or url], [new_file_name]);

Simple use with default image resolution

<?= Yii::$app->avatar->show('John Smith') ?>

Image with 150 px sides

<?= Yii::$app->avatar->show('John Smith', 150) ?>

Image for existing file with default image resolution

<?= Yii::$app->avatar->show('John Smith', null, '/path/JM_Avatar.jpg') ?>

or

<?= Yii::$app->avatar->show('John Smith', null, 'http://site.org/JM_Avatar.jpg') ?>

Image for existing file with 150 px sides

<?= Yii::$app->avatar->show('John Smith', 150, '/path/JM_Avatar.jpg') ?>

Using without Yii2 wrap

You can use avatar generator without Yii2 wrap. Just install https://github.com/zertex/avatar-generator

Screenshot

alt text

Examples

https://zertex.ru/yii2-avatar-generator

统计信息

  • 总下载量: 4.44k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2018-06-26