PHPackages                             sabirov/yii2-bootstrap4-cropper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sabirov/yii2-bootstrap4-cropper

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

sabirov/yii2-bootstrap4-cropper
===============================

Cropper for Yii2

0.1.4(5y ago)1195[1 issues](https://github.com/sabirov/yii2-bootstrap4-cropper/issues)MITPHPPHP &gt;=5.4.0

Since Jan 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/sabirov/yii2-bootstrap4-cropper)[ Packagist](https://packagist.org/packages/sabirov/yii2-bootstrap4-cropper)[ RSS](/packages/sabirov-yii2-bootstrap4-cropper/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (4)Versions (9)Used By (0)

Yii2 Bootstrap4 Image Cropper InputWidget
=========================================

[](#yii2-bootstrap4-image-cropper-inputwidget)

Cropper for Yii2 which uses Bootstrap4.

Wrapper for [cropperjs](https://github.com/fengyuanchen/cropperjs).

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require sabirov/yii2-bootstrap4-cropper

```

or add

```
"sabirov/yii2-bootstrap4-cropper": "^0.1.1"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

In your model you need to add the following code :

```
    public $_avatar;    // variable to get the picture

    public function rules()
    {
        return [
            ['_avatar', 'safe'],    // must be set to "safe"
        ];
    }

    public function beforeSave($insert)
    {
        if (is_string($this->_avatar) && strstr($this->_avatar, 'data:image')) {
            $uploadPath = Yii::getAlias('@web') . '/upload';    // set a directory to save picture
            $data = $this->_avatar;
            $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
            $fileName = Yii::$app->security->generateRandomString() . '.png';   // generate picture name
            file_put_contents($uploadPath . DIRECTORY_SEPARATOR . $fileName, $data);

            if (!empty($this->avatar)) {    // "avatar" model attribute which stores picture name
                unlink(Yii::getAlias($uploadPath . DIRECTORY_SEPARATOR . $this->avatar));   // delete old picture
            }

            $this->avatar = $fileName;  // set new picture name to attribute
        }

        return parent::beforeSave($insert);
    }
```

Simple usage in view file
-------------------------

[](#simple-usage-in-view-file)

```
use sabirov\cropper\Cropper;

$uploadPath = Yii::getAlias('@web') . '/upload';
$img_url = is_null($model->avatar) ? null : $uploadPath . DIRECTORY_SEPARATOR . $model->avatar;

$form = ActiveForm::begin();

echo $form->field($model, '_avatar')->widget(Cropper::class, [
    'previewImageUrl' => $img_url,  // if 'null' set url to no-image.svg
]);

echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);

ActiveForm::end();
```

Advanced usage in view file
---------------------------

[](#advanced-usage-in-view-file)

```
use sabirov\cropper\Cropper;

$uploadPath = Yii::getAlias('@web') . '/upload';
$img_url = is_null($model->avatar) ? null : $uploadPath . DIRECTORY_SEPARATOR . $model->avatar;

$form = ActiveForm::begin();

echo $form->field($model, '_avatar')->widget(Cropper::class, [
    'previewImageUrl' => $img_url,  // if 'null' set url to no-image.svg
    'extensionOptions' => [
        'preview' => [
            'width' => 270,
            'height' => 270
        ],
        'browseButtonText' => 'Выбрать',
        'cropButtonText' => 'Обрезать',
        'changeButtonText' => 'Изменить',
        'closeButtonText' => 'Закрыть',
        'cropperWarningText' => 'Двойной клик - переключение между перемещением изображения и выбором области обрезки.'
    ],
    'cropperOptions' => [
        'viewMode' => 1,
        'aspectRatio' => 1,
        'minContainerHeight' => 270,
        'minCropBoxHeight' => 270
    ]
]);

echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);

ActiveForm::end();
```

**extensionOptions** properties:

NameDescriptionDefaultRequiredpreviewArray consisting of 'width' and 'height' parameters of preview image, may be with 'px', '%' and without any.\[ 'width' =&gt; '100px','height' =&gt; '300px'\]NObrowseButtonTextText in 'browse' button.'Browse'NOcropButtonTextText in 'crop' button.'Crop'NOchangeButtonTextText in 'change' button.'Change'NOcloseButtonTextText in 'close' button.'Close'NOcropperWarningTextText of warning which displayed below cropped image'Double-click to switch between moving the image and selecting the cropping area.'NO**cropperOptions** see [cropperjs options](https://github.com/fengyuanchen/cropperjs/blob/master/README.md#options).

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~104 days

Recently: every ~182 days

Total

8

Last Release

1950d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1768e9efd92d40bc9f5e21e3ba3c008e9ab28b928c6a906118defe103cbc06c3?d=identicon)[Sabirov](/maintainers/Sabirov)

---

Top Contributors

[![sabirov](https://avatars.githubusercontent.com/u/4890101?v=4)](https://github.com/sabirov "sabirov (133 commits)")

---

Tags

yii2extensioncropper

### Embed Badge

![Health badge](/badges/sabirov-yii2-bootstrap4-cropper/health.svg)

```
[![Health](https://phpackages.com/badges/sabirov-yii2-bootstrap4-cropper/health.svg)](https://phpackages.com/packages/sabirov-yii2-bootstrap4-cropper)
```

###  Alternatives

[hail812/yii2-adminlte-widgets

yii2 adminlte widgets

10246.8k4](/packages/hail812-yii2-adminlte-widgets)[romka-chev/yii2-swiper

Yii2 extension for Swiper slider

1840.6k](/packages/romka-chev-yii2-swiper)[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
