-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
38 lines (29 loc) · 1.07 KB
/
process.php
File metadata and controls
38 lines (29 loc) · 1.07 KB
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
<?php
require_once './vendor/autoload.php';
use Imagine\Image\Point;
use Imagine\Image\Box;
$file = $_FILES['file'];
$post = $_POST;
$targ_w = (int)$post['crop_img_width'];
$targ_h = (int)$post['crop_img_height'];
$croppedX = (int)$post['horizonatal_pos'];
$croppedY = (int)$post['vertical_pos'];
if (is_array($file) && isset($file['name'])) {
$uniqueFileName = uniqid('ff') . $file['name'];
if (!file_exists(__DIR__ . '/storage')) {
mkdir(__DIR__ . '/storage');
}
$destination = './storage/' . $uniqueFileName;
if ($file['error'] == 0) {
move_uploaded_file($file['tmp_name'], $destination);
$croppeedImg = 'cropped-' . $uniqueFileName;
$croppedDestination = './storage/' . $croppeedImg;
$image = new \Imagine\Gd\Imagine();
$img = $image->open($destination);
$img->crop(new Point($croppedX, $croppedY), new Box($targ_w, $targ_h))
->save($croppedDestination);
unlink($destination);
}
} else {
}
header('Location:index.php?path=' . $croppedDestination);