ereminmdev / yii2-cropperimageupload
Image crop and upload for Yii framework.
Installs: 1 021
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.4
- mohorev/yii2-upload-behavior: ^0.2
- npm-asset/cropperjs: ^1.0
- yiisoft/yii2: ~2.0.1
- yiisoft/yii2-imagine: ^2.1
- dev-main
- 1.0.66
- 1.0.65
- 1.0.64
- 1.0.63
- 1.0.62
- 1.0.61
- 1.0.60
- 1.0.59
- 1.0.58
- 1.0.57
- 1.0.56
- 1.0.55
- 1.0.54
- 1.0.53
- 1.0.52
- 1.0.51
- 1.0.50
- 1.0.49
- 1.0.48
- 1.0.47
- 1.0.46
- 1.0.45
- 1.0.44
- 1.0.43
- 1.0.42
- 1.0.41
- 1.0.40
- 1.0.39
- 1.0.38
- 1.0.37
- 1.0.36
- 1.0.35
- 1.0.34
- 1.0.33
- v1.0.32
- v1.0.31
- v1.0.30
- v1.0.29
- v1.0.28
- v1.0.27
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
This package is auto-updated.
Last update: 2025-02-20 13:00:02 UTC
README
Image crop and upload for Yii framework.
Depends on:
Install
composer require --prefer-dist ereminmdev/yii-cropperimageupload
Use
Add some code to model and view files:
- model:
public function behaviors() { return [ 'avatar' => [ 'class' => CropperImageUploadBehavior::class, 'attribute' => 'avatar', 'scenarios' => ['default', 'create', 'update'], 'placeholder' => '@app/modules/user/assets/images/no-avatar.jpg', 'path' => '@webroot/upload/avatar/{id}', 'url' => '@web/upload/avatar/{id}', 'thumbs' => [ 'thumb' => ['width' => 60, 'height' => 60, 'quality' => 80, 'mode' => ManipulatorInterface::THUMBNAIL_OUTBOUND], 'preview' => ['width' => 240, 'height' => 240, 'bg_alpha' => 0], ], 'cropAspectRatio' => 1, ], ]; } public function rules() { return [ [['avatar'], 'file', 'extensions' => 'jpg, jpeg, gif, png, svg, webp'], ]; }
- form field:
<?= $form->field($model, 'avatar')->widget(CropperImageUploadWidget::class) ?>
- html image:
<?= $model->renderThumbImage('avatar') ?> <?= $model->renderThumbImage('avatar', 'preview', ['alt' => 'Avatar']) ?>
Tips
- Re-create thumbs:
foreach (User::find()->each() as $model) { $filename = $model->getAttribute('avatar'); if ($model->recreateThumbs('avatar', true, true)) { $this->stdout('Recreated successful: ' . $filename . "\n"); } else { $this->stdout('Error when recreating: ' . $filename . "\n", Console::FG_RED); } }