germanoricardi/yii2-imagecrop
Composer 安装命令:
composer require germanoricardi/yii2-imagecrop
包简介
PHP class to crop images with yii2
README 文档
README
yii2-imagecrop
Crop images with this class is very simple!
Resources
- Centralized autocrop;
- Customized cutting area with json;
- Watermark;
Installation
The preferred way to install this extension is through composer.
Install
Either run
$ php composer.phar require germanoricardi/yii2-imagecrop "*"
or add
"germanoricardi/yii2-imagecrop": "*"
to the require section of your composer.json file.
**Part of this class code was implemented by a document made available by fengyuanchen.
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.
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:
$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
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-22