-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_crop.php
More file actions
49 lines (46 loc) · 1.54 KB
/
image_crop.php
File metadata and controls
49 lines (46 loc) · 1.54 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
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Created by Zhufyak V.V.
* User: zhufy
* E-mai: zhufyakvv@gmail.com
* Git: https://github.com/zhufyakvv
* Date: 15.05.2017
* Time: 8:00
*/
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$uploaddir = __DIR__.'\img\\';
$image_path = $uploaddir . basename($_FILES['image']['name']);
move_uploaded_file($_FILES['image']['tmp_name'], $image_path);
$image = imagecreatefrompng($image_path);
$croped = imagecrop($image, ['x' => $_POST['x'], 'y' => $_POST['y'], 'width' => $_POST['w'], 'height' => $_POST['h']]);
if ($croped !== FALSE) {
$croped_path = $uploaddir."\croped\\".basename($_FILES['image']['name']);
imagepng($croped, $croped_path);
header('Content-type: image/png');
echo file_get_contents($croped_path);
//header('Content-Disposition: attachment; filename="croper.png"');
}
}else{
?>
<html>
<head>
<title>Image crop</title>
<meta charset="utf-8">
<link rel="stylesheet" href="style/form-style.css">
</head>
<body>
<div class="form_holder">
<div class="form">
<form enctype="multipart/form-data" method="post" >
<input name = "image" type="file" accept="image/png">
<input name = "x" type="number" placeholder="x">
<input name = "y" type="number" placeholder="y">
<input name = "w" type="number" placeholder="w">
<input name = "h" type="number" placeholder="h">
<input type="submit">
</form>
</div>
</div>
</body>
</html>
<?php } ?>