PHP code example of flash20 / yii2-avatar

1. Go to this page and download the library: Download flash20/yii2-avatar 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/ */

    

flash20 / yii2-avatar example snippets



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


放到Form里

<?= $form->field($model, 'avatar')->widget(\flash20\avatar\AvatarViewWidget::className())