PHP code example of huanguang / yii2avatar

1. Go to this page and download the library: Download huanguang/yii2avatar library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

huanguang / yii2avatar example snippets



//在当前控制器的actions中添加如下配置
public function actions()
{
    return [
        'crop'=>[
            'class' => 'huanguang\avatar\CropAction',
            'config'=>[
                'bigImageWidth' => '200',     //大图默认宽度
                'bigImageHeight' => '200',    //大图默认高度
                'middleImageWidth'=> '100',   //中图默认宽度
                'middleImageHeight'=> '100',  //中图图默认高度
                'smallImageWidth' => '50',    //小图默认宽度
                'smallImageHeight' => '50',   //小图默认高度
                
                //头像上传目录(注:目录前不能加"/")
                'uploadPath' => 'uploads/avatar',
            ],
            'baseUrl' => '@web/upload/avatar',//访问目录
            'basePath' => '@webroot/upload/avatar',//磁盘目录
        ]
    ]; 
    
}
 
//调用方式,imageUrl为默认图地址 234
<?= \huanguang\yii2avatar\AvatarWidget::widget(['imageUrl'=>'/statics/images/avatar/avatar_1.jpg']);