, (*1)
yii2-imagecrop
Crop images with this class is very simple!, (*2)
Resources
- Centralized autocrop;
- Customized cutting area with json;
- Watermark;
Installation
The preferred way to install this extension is through composer., (*3)
Install
Either run, (*4)
$ php composer.phar require germanoricardi/yii2-imagecrop "*"
or add, (*5)
"germanoricardi/yii2-imagecrop": "*"
to the require
section of your composer.json
file., (*6)
_**Part of this class code was implemented by a document made available by fengyuanchen_., (*7)
How to use
Add the following code in a controller, the image that will be used for cutting should already be on your server, that is, the code should be run after the file upload. The original image is always preserved., (*8)
use germanoricardi\imagecrop\ImageCrop;
public function actionCrop(){
$imageCrop = new ImageCrop();
$imageCrop->imageSourcePath = '@webroot/medias/';
$imageCrop->imagesSizes = [
['path' => '@webroot/medias/thumbs/', 'width' => '200', 'height' => '200'],
['path' => '@webroot/medias/large/', 'width' => '800', 'height' => '600', 'watermark' => '@webroot/watermark.png']
];
$imageCrop->imageFileName = 'image-to-crop.jpg';
$imageCrop->init();
}
AJAX
If you are working with a jQuery plugin for crop image parameters can be passed to the class via AJAX as follows:, (*9)
$imageCrop = new ImageCrop();
$imageCrop->imageSourcePath = '@webroot/medias/';
$imageCrop->imagesSizes = [
['path' => '@webroot/medias/thumbs/', 'width' => '200', 'height' => '200'],
['path' => '@webroot/medias/large/', 'width' => '800', 'height' => '600', 'watermark' => '@webroot/watermark.png']
];
$imageCrop->imageFileName = 'image-to-crop.jpg';
// AJAX
$imageCrop->data = '{"x":220,"y":26,"width":1168,"height":1168,"rotate":0,"scaleX":1,"scaleY":1}';
$imageCrop->init();
License
, (*10)