-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cropper.php
executable file
·50 lines (37 loc) · 1.2 KB
/
Cropper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* @copyright Copyright (c) 2014 Let.,ltd
* @author Ngua Go <nguago@let.vn>
*/
namespace letyii\cropper;
use yii\helpers\Json;
use yii\helpers\FileHelper;
use yii\imagine\BaseImage;
class Cropper
{
public $data;
public $file;
public $fileName;
public $folder;
private function getData(){
return Json::decode($this->data);
}
public function crop() {
$this->saveOriginal();
}
private function saveOriginal() {
if (($ext = pathinfo($this->file, PATHINFO_EXTENSION)) !== '')
$ext = strtolower($ext);
FileHelper::createDirectory($this->folder);
$path = $this->folder . DIRECTORY_SEPARATOR;
$imageOriginal = $path . $this->fileName . '.original.' . $ext;
// Neu anh la anh moi upload
if (is_object($this->file)){
$this->file->saveAs($imageOriginal);
}
// Get data image crop
$data = $this->getData();
// Crop image and save image
BaseImage::crop($imageOriginal, $data['width'], $data['height'], [$data['x'], $data['y']])->rotate($data['rotate'])->save($path . $this->fileName . '.' . $ext);
}
}