PHPackages                             specialist/yii2-crop-image-upload - 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. specialist/yii2-crop-image-upload

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

specialist/yii2-crop-image-upload
=================================

Yii 2 Crop image upload widget

027JavaScript

Since Oct 10Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Specialist001/yii2-crop-image-upload)[ Packagist](https://packagist.org/packages/specialist/yii2-crop-image-upload)[ RSS](/packages/specialist-yii2-crop-image-upload/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

cropped image upload extension for Yii2
=======================================

[](#cropped-image-upload-extension-for-yii2)

[![Latest Stable Version](https://camo.githubusercontent.com/32d52e1ffb525fe6ac5f55e9c51a8ba881319eedb612b70e52767b75a2214980/68747470733a2f2f706f7365722e707567782e6f72672f7370656369616c6973742f796969322d63726f702d696d6167652d75706c6f61642f762f737461626c652e737667)](https://packagist.org/packages/specialist/yii2-crop-image-upload) [![Total Downloads](https://camo.githubusercontent.com/169e88ac34afa31765c01dae3a2f2ce06e8a508841f37a6add19fd88cc617df7/68747470733a2f2f706f7365722e707567782e6f72672f7370656369616c6973742f796969322d63726f702d696d6167652d75706c6f61642f646f776e6c6f6164732e737667)](https://packagist.org/packages/specialist/yii2-crop-image-upload) [![Latest Unstable Version](https://camo.githubusercontent.com/72017c5b828da2c5929c95399cda414572ca0a6142d3b3666936da50da91e67a/68747470733a2f2f706f7365722e707567782e6f72672f7370656369616c6973742f796969322d63726f702d696d6167652d75706c6f61642f762f756e737461626c652e737667)](https://packagist.org/packages/specialist/yii2-crop-image-upload) [![License](https://camo.githubusercontent.com/07ac8ee6fb983087c6be3c6d6b29f482153320c3c1dd89ec3ec836b5078c53ad/68747470733a2f2f706f7365722e707567782e6f72672f7370656369616c6973742f796969322d63726f702d696d6167652d75706c6f61642f6c6963656e73652e737667)](https://packagist.org/packages/specialist/yii2-crop-image-upload)

This extension automatically uploads image and make crop.

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

[](#installation)

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

Either run

```
php composer.phar require specialist/yii2-crop-image-upload "@dev"

```

or add

```
"specialist/yii2-crop-image-upload": "@dev"
```

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

Usage
-----

[](#usage)

### Upload image and create crop

[](#upload-image-and-create-crop)

Attach the behavior in your model:

```
use specialist\icrop\CropImageUploadBehavior;

class Document extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            ['photo', 'file', 'extensions' => 'jpeg, gif, png', 'on' => ['insert', 'update']],
        ];
    }

    /**
     * @inheritdoc
     */
    function behaviors()
    {
        return [
            [
                'class' => CropImageUploadBehavior::className(),
                'attribute' => 'photo',
                'scenarios' => ['insert', 'update'],
                'path' => '@webroot/upload/docs',
                'url' => '@web/upload/docs',
				'ratio' => 1,
				'crop_field' => 'photo_crop',
				'cropped_field' => 'photo_cropped',
            ],
        ];
    }
}
```

Example view file:

```
