zertex/yii2-avatar-generator Avatar generator for Yii2 Framework.

Avatar Generator

  1. Features
  2. Dependencies
  3. Installation
  4. Configuration
  5. Using
  6. Screenshot
  7. Examples

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 `html <?= Yii::$app->avatar->show('John Smith') ?> `

Image with 150 px sides `html <?= Yii::$app->avatar->show('John Smith', 150) ?> `

Image for existing file with default image resolution `html <?= Yii::$app->avatar->show('John Smith', null, '/path/JM_Avatar.jpg') ?> orhtml <?= Yii::$app->avatar->show('John Smith', null, 'http://site.org/JM_Avatar.jpg') ?> `

Image for existing file with 150 px sides `html <?= 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

1 0
1 follower
300 downloads
Yii Version: 2.0
License: BSD-3-Clause
Category: User Interface
Tags: avatar
Developed by: Error202
Created on: Jun 26, 2018
Last updated: (not set)
Packagist Profile
Github Repository

Related Extensions