PHP code example of opqnext / yii2-avatar

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

    

opqnext / yii2-avatar example snippets


composer 

// imageUrl 是当前用户头像地址(当前未上传头像则为默认图片)
<?= \opqnext\avatar\AvatarWidget::widget(['imageUrl'=>'https://image.opqnext.com/logo.jpg'])


$cssString = ".modal-dialog{left:auto;width:900px;}";
$this->registerCss($cssString);

public function actionAvatar()
{
    \Yii::$app->response->format=Response::FORMAT_JSON;
    
    // 注意按需分配图片上传地址。
    $clip = new ClipUploadAvatar(
        isset($_POST['avatar_src']) ? $_POST['avatar_src'] : null,
        isset($_POST['avatar_data']) ? $_POST['avatar_data'] : null,
        isset($_FILES['avatar_file']) ? $_FILES['avatar_file'] : null,
        \Yii::getAlias('@webroot').'/img/avatar'
    );
    $response = array(
        'state'  => 200,
        'message' => $clip->getMsg(),
        'result' => \Yii::getAlias('@web').'/img/avatar/'.$clip->getResult()
    );
    
    // ...存储数据库等

    return $response;
}