conquer / jcrop
Yii2 Jcrop widget
1.1.0
2026-11-07 05:22 UTC
Requires
- php: ^7.4 || ^8.0
- bower-asset/jcrop: ^2.0.4
- conquer/helpers: ^2.0.7
- yiisoft/yii2: ~2.0.14
Requires (Dev)
- phpunit/phpunit: ^9.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-07 05:30:39 UTC
README
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.