PHPackages                             dbfernandes/yii2-cropper-cb - 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. [Image &amp; Media](/categories/media)
4. /
5. dbfernandes/yii2-cropper-cb

ActiveYii2-extension[Image &amp; Media](/categories/media)

dbfernandes/yii2-cropper-cb
===========================

Yii2 Bootstrap Cropper Input (forked from bilginnet/yii2-cropper)

021JavaScript

Since Nov 15Pushed 8y agoCompare

[ Source](https://github.com/dbfernandes/yii2-cropper-1)[ Packagist](https://packagist.org/packages/dbfernandes/yii2-cropper-cb)[ RSS](/packages/dbfernandes-yii2-cropper-cb/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

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

Forked from Ercan Bilgin (). Original repository: bilginnet/yii2-cropper.

CB.

Features
--------

[](#features)

- Crop
- Image Rotate
- Image Flip
- Image Zoom
- Coordinates
- Image Sizes Info
- Base64 Data

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist dbfernandes/yii2-cropper-cb "dev-master"

```

or add

```
"dbfernandes/yii2-cropper-cb": "dev-master"

```

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

Usage
-----

[](#usage)

Let's add into config in your main-local config file before return\[\]

```
       $baseUrl = str_replace('/backend/web', '', (new Request)->getBaseUrl());
       $baseUrl = str_replace('/frontend/web', '', $baseUrl);

       Yii::setAlias('@uploadUrl', $baseUrl.'/uploads/');
       Yii::setAlias('@uploadPath', realpath(dirname(__FILE__).'/../../uploads/'));
       // image file will upload in //root/uploads   folder

       return [
           ....
       ]
```

Let's add in your model file

```
    public $_image

    public function rules()
    {
        return [
            ['_image', 'safe'],
        ];
    }

    public function beforeSave($insert)
    {
        if (is_string($this->_image) && strstr($this->_image, 'data:image')) {

            // creating image file as png
            $data = $this->_image;
            $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
            $fileName = time() . '-' . rand(100000, 999999) . '.png';
            file_put_contents(Yii::getAlias('@uploadPath') . '/' . $fileName, $data);

            // deleting old image
            // $this->image is real attribute for filename in table
            // customize your code for your attribute
            if (!$this->isNewRecord && !empty($this->image)) {
                unlink(Yii::getAlias('@uploadPath/'.$this->image));
            }

            // set new filename
            $this->image = $fileName;
        }

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

Advanced usage in \_form file
-----------------------------

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

```
 echo $form->field($model, '_image')->widget(\dbfernandes\cropper\Cropper::className(), [
    'cropperOptions' => [
        'width' => 100, // must be specified
        'height' => 100, // must be specified

        // optional
        // url must be set in update action
        'preview' => [
            'url' => '', // set in update action // (!$model->isNewRecord) ? Yii::getAlias('@uploadUrl/$model->image') : ''
            'width' => 100, // default 100 // default is cropperWidth if cropperWidth < 100
            'height' => 100, // Will calculate automatically by aspect ratio if not set
        ],

        // optional // defaults following code
        // you can customize
        'icons' => [
            'browse' => '',
            'crop' => '',
            'close' => '',
        ]
    ],

    // optional // defaults following code
    // you can customize
    'label' => '$model->attribute->label',

 ]);
```

Simple usage in \_form file
---------------------------

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

```
 echo $form->field($model, '_image')->widget(\dbfernandes\cropper\Cropper::className(), [
    'cropperOptions' => [
        'width' => 100, // must be specified
        'height' => 100, // must be specified
     ]
]);
```

Notes
-----

[](#notes)

Don't forget to add this line into root in .htaccess file

```
RewriteRule ^uploads/(.*)$ uploads/$1 [L]

```

I will add jsOptions\[\] soon
-----------------------------

[](#i-will-add-jsoptions-soon)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 54.3% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/869f23dda89fb8134de7fdd8303c8c9bc9ce8c129845becf530c5be3aab0641c?d=identicon)[dbfernandes](/maintainers/dbfernandes)

---

Top Contributors

[![bilginnet](https://avatars.githubusercontent.com/u/8385372?v=4)](https://github.com/bilginnet "bilginnet (19 commits)")[![dbfernandes](https://avatars.githubusercontent.com/u/3472503?v=4)](https://github.com/dbfernandes "dbfernandes (16 commits)")

### Embed Badge

![Health badge](/badges/dbfernandes-yii2-cropper-cb/health.svg)

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

###  Alternatives

[milon/barcode

Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)

1.5k13.3M39](/packages/milon-barcode)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[char0n/ffmpeg-php

PHP wrapper for FFmpeg application

495225.1k1](/packages/char0n-ffmpeg-php)[goat1000/svggraph

Generates SVG graphs

132849.6k3](/packages/goat1000-svggraph)[cohensive/embed

Media Embed (for Laravel or as a standalone).

120370.4k](/packages/cohensive-embed)[netresearch/rte-ckeditor-image

Image support in CKEditor for the TYPO3 ecosystem - by Netresearch

63991.3k4](/packages/netresearch-rte-ckeditor-image)

PHPackages © 2026

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