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 2w 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 13% 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://avatars.githubusercontent.com/u/3472503?v=4)[David Fernandes de Oliveira](/maintainers/dbfernandes)[@dbfernandes](https://github.com/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

[goat1000/svggraph

Generates SVG graphs

133890.0k3](/packages/goat1000-svggraph)[imagekit/imagekit

PHP library for Imagekit

46877.3k10](/packages/imagekit-imagekit)[gravatarphp/gravatar

Gravatar URL builder which is most commonly called as a Gravatar library

12644.1k2](/packages/gravatarphp-gravatar)

PHPackages © 2026

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