maxmirazh33/yii2-uploadable-cropable-image
最新稳定版本:v2.2.5
Composer 安装命令:
composer require maxmirazh33/yii2-uploadable-cropable-image
包简介
Yii2 extension for upload and crop images
README 文档
README
Yii2 extension for upload and crop images
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist maxmirazh33/yii2-uploadable-cropable-image "*"
or add
"maxmirazh33/yii2-uploadable-cropable-image": "*"
to the require section of your composer.json file.
Usage
Once the extension is installed, simply use it in your code by :
In your model:
public function behaviors() { return [ [ 'class' => \maxmirazh33\image\Behavior::className(), 'savePathAlias' => '@web/images/', 'urlPrefix' => '/images/', 'crop' => true, 'attributes' => [ 'avatar' => [ 'savePathAlias' => '@web/images/avatars/', 'urlPrefix' => '/images/avatars/', 'width' => 100, 'height' => 100, ], 'logo' => [ 'crop' => false, 'thumbnails' => [ 'mini' => [ 'width' => 50, ], ], ], ], ], //other behaviors ]; }
Use rules for validate attribute.
In your view file:
echo $form->field($model, 'avatar')->widget('maxmirazh33\image\Widget');
After, in your view:
echo Html::img($model->getImageUrl('avatar')); echo Html::img($model->getImageUrl('logo', 'mini')); //get url of thumbnail named 'mini' for 'logo' attribute
If you use Advanced App Template and this behavior attached in backend model, then in frontend model add trait
use \maxmirazh33\image\GetImageUrlTrait
and use getImageUrl() method for frontend model too.
统计信息
- 总下载量: 20.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-04