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

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

demi/cropper
============

Yii2 wrapper for Image Cropper javascript library

1.2.0(8y ago)1328.7k↓31.3%4[1 PRs](https://github.com/demisang/yii2-cropper/pulls)1GNUPHPPHP &gt;=5.4.0

Since Jun 19Pushed 8y ago4 watchersCompare

[ Source](https://github.com/demisang/yii2-cropper)[ Packagist](https://packagist.org/packages/demi/cropper)[ Docs](https://github.com/demisang/yii2-cropper#readme)[ RSS](/packages/demi-cropper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (1)

Yii2-cropper
============

[](#yii2-cropper)

Wrapper for [Image Cropper](http://fengyuanchen.github.io/cropper/) javascript library

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

[](#installation)

Run

```
composer require "demi/cropper" "~1.0"

```

Usage
=====

[](#usage)

---

*hint: functionality of this extension is already implemented into my extension to [image uploading](https://github.com/demisang/yii2-image-uploader)*

```
echo Cropper::widget([
    // If true - it's output button for toggle modal crop window
    'modal' => true,
    // You can customize modal window. Copy /vendor/demi/cropper/views/modal.php
    'modalView' => '@backend/views/image/custom_modal',
    // URL-address for the crop-handling request
    // By default, sent the following post-params: x, y, width, height, rotate
    'cropUrl' => ['cropImage', 'id' => $image->id],
    // Url-path to original image for cropping
    'image' => Yii::$app->request->baseUrl . '/images/' . $image->src,
    // The aspect ratio for the area of cropping
    'aspectRatio' => 4 / 3, // or 16/9(wide) or 1/1(square) or any other ratio. Null - free ratio
    // Additional params for JS cropper plugin
    'pluginOptions' => [
        // All possible options: https://github.com/fengyuanchen/cropper/blob/master/README.md#options
        'minCropBoxWidth' => 400, // minimal crop area width
        'minCropBoxHeight' => 300, // minimal crop area height
    ],
    // HTML-options for widget container
    'options' => [],
    // HTML-options for cropper image tag
    'imageOptions' => [],
    // Translated messages
    'messages' => [
        'cropBtn' => Yii::t('app', 'Crop'),
        'cropModalTitle' => Yii::t('app', 'Select crop area and click "Crop" button'),
        'closeModalBtn' => Yii::t('app', 'Close'),
        'cropModalBtn' => Yii::t('app', 'Crop selected'),
    ],
    // Additional ajax-options for send crop-request. See jQuery $.ajax() options
    'ajaxOptions' => [
        'success' => new JsExpression(
