Search by

conquer / jcrop

borodulin

Yii2 Jcrop widget

Package info

github.com/borodulin/yii2-jcrop

Type:yii2-extension

pkg:composer/conquer/jcrop

Statistics

Installs: 156

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.1.0 2026-11-07 05:22 UTC

This package is auto-updated.

Last update: 2026-11-07 05:30:39 UTC


README

Latest Version Total Downloads CI License

Description

Image cropping with Jcrop 2.

Requirements

  • PHP 7.4 or 8.x
  • Yii 2.0.14 or later
  • asset-packagist repository configured in your application's composer.json (standard for Yii2 app templates)

Installation

composer require conquer/jcrop:^1.1

Usage

use conquer\jcrop\JcropWidget;

<?= JcropWidget::widget([
    'src' => '@web/images/photo.jpg',
    'options' => ['aspectRatio' => 1],
    // `this` is the Jcrop API
    'invocation' => 'function () {
        this.container.on("cropmove cropend", function (e, selection, c) {
            jQuery("#crop-x").val(Math.round(c.x));
            jQuery("#crop-y").val(Math.round(c.y));
            jQuery("#crop-w").val(Math.round(c.w));
            jQuery("#crop-h").val(Math.round(c.h));
        });
        this.newSelection();
        this.setSelect([0, 0, 200, 200]);
    }',
]) ?>

The coordinates are in pixels of the original image. Check them on the server before cropping: they come from the browser.

Property Default Description
src null Image URL, see yii\helpers\Url::to()
options [] Jcrop options; strings with the js: prefix are JavaScript expressions, never put user data there
invocation null JavaScript function called when Jcrop is ready
htmlOptions [] HTML attributes of the container
tag 'img' Container tag; with begin()/end() use e.g. div around your own content

Only js/Jcrop.min.js and the styles are published. The Jcrop package also contains demos, jQuery 1.9 and a PHP script that must not be web-accessible.

License

conquer/jcrop is released under the MIT License. See the bundled LICENSE for details. Jcrop is released under the MIT License.