specialist / yii2-cropper
Yii2 framework widget for uploading and cropping images
Installs: 51
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- bower-asset/jcrop: =0.9.12
- bower-asset/simple-ajax-uploader: 2.6.1
- yiisoft/yii2: *
- yiisoft/yii2-imagine: *
This package is auto-updated.
Last update: 2024-11-19 18:31:29 UTC
README
Yii-Framework extension for uploading and cropping images.
Installation
The preferred way to install this extension is through composer.
Either run
composer require specialist/yii2-cropper "dev-master"
or add
"specialist/yii2-cropper": "dev-master"
to the require section of your composer.json
file.
Usage
Once the extension is installed, simply use it in your code by :
use specialist\cropper\CropperWidget;
<?php $form = ActiveForm::begin(['id' => 'form-profile']); ?>
<?php echo $form->field($model, 'photo')->widget(CropperWidget::className(), [
'uploadUrl' => Url::toRoute('/controller-name/upload-photo'), // 'uploadUrl' => Url::toRoute('/category/upload-photo')
'width' => 300,
'height' => 300,
]) ?>
<div class="form-group">
<?php echo Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
Widget has following properties:
In UserController:
use specialist\cropper\actions\UploadAction;
public function actions()
{
return [
'upload-photo' => [
'class' => UploadAction::className(),
'url' => '../../uploads/', //you must create 'uploads' directory in your root directory -> '../../uploads/categories/'
'path' => '../../uploads/', //you must create 'uploads' directory in your root directory
]
];
}
Action has following parameters: