项目作者: daimakuai

项目描述 :
yii2-avatar
高级语言: JavaScript
项目地址: git://github.com/daimakuai/yii2-avatar.git
创建时间: 2017-12-14T10:07:03Z
项目社区:https://github.com/daimakuai/yii2-avatar

开源协议:

下载


头像上传

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

@from 代码块中文网 (www.daimakuai.com)

截图

daimakuai

Installation

The preferred way to install this extension is through composer.

Either run

  1. php composer.phar require --prefer-dist daimakuai/yii2-avatar "dev-master"

or add

  1. "daimakuai/yii2-avatar": "dev-master"

to the require section of your composer.json file.

Usage

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

  1. //在当前控制器的actions中添加如下配置
  2. public function actions()
  3. {
  4. return [
  5. 'crop'=>[
  6. 'class' => 'daimakuai\avatar\CropAction',
  7. 'config'=>[
  8. 'bigImageWidth' => '200', //大图默认宽度
  9. 'bigImageHeight' => '200', //大图默认高度
  10. 'middleImageWidth'=> '100', //中图默认宽度
  11. 'middleImageHeight'=> '100', //中图图默认高度
  12. 'smallImageWidth' => '50', //小图默认宽度
  13. 'smallImageHeight' => '50', //小图默认高度
  14. //头像上传目录(注:目录前不能加"/")
  15. 'uploadPath' => 'uploads/avatar',
  16. ]
  17. ]
  18. ];
  19. }
  20. //调用方式,imageUrl为默认图地址
  21. <?= \daimakuai\avatar\AvatarWidget::widget(['imageUrl'=>'/statics/images/avatar/avatar.jpg']); ?>

在From里可以单独使用

  1. 放到Form
  2. <?= $form->field($model, 'avatar')->widget(\daimakuai\avatar\AvatarViewWidget::className()) ?>
  3. 放到Form
  4. <?php $obj = new \daimakuai\avatar\AvatarUploadWidget(['imageUrl'=>'/statics/images/avatar/avatar.jpg']);echo $obj->setFooter(); ?>