PHPackages                             hyii2/yii2-avatar - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. hyii2/yii2-avatar

ActiveYii2-extension[File &amp; Storage](/categories/file-storage)

hyii2/yii2-avatar
=================

基于cropper的一款头像上传yii2组件

3382415[2 issues](https://github.com/org-yii-china/yii2-avatar/issues)JavaScript

Since Aug 1Pushed 9y ago5 watchersCompare

[ Source](https://github.com/org-yii-china/yii2-avatar)[ Packagist](https://packagist.org/packages/hyii2/yii2-avatar)[ RSS](/packages/hyii2-yii2-avatar/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

头像上传
====

[](#头像上传)

基于cropper的一款头像上传yii2组件,

@from Yii中文网（[www.yii-china.com](http://www.yii-china.com)）

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist hyii2/yii2-avatar "dev-master"

```

or add

```
"hyii2/yii2-avatar": "dev-master"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your code by :

```
//在当前控制器的actions中添加如下配置
public function actions()
{
    return [
        'crop'=>[
            'class' => 'hyii2\avatar\CropAction',
            'config'=>[
                'bigImageWidth' => '200',     //大图默认宽度
                'bigImageHeight' => '200',    //大图默认高度
                'middleImageWidth'=> '100',   //中图默认宽度
                'middleImageHeight'=> '100',  //中图图默认高度
                'smallImageWidth' => '50',    //小图默认宽度
                'smallImageHeight' => '50',   //小图默认高度

                //头像上传目录（注：目录前不能加"/"）
                'uploadPath' => 'uploads/avatar',
            ]
        ]
    ];

}

//调用方式,imageUrl为默认图地址
