-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage-crop.php
executable file
·79 lines (69 loc) · 2.25 KB
/
image-crop.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
$image = 'pic/flower.jpg'; // the image to crop
$dest_image = 'pic/cropped_whatever.jpg'; // make sure the directory is writeable
$margin = 10; // to keep the image and layer in sync
if(!isset($_POST['step'])) $title = '1';
else $title = $_POST['step'];
echo '
<html>
<head>
<title>lixlpixel image crop | step '.$title.'</title>
</head>
<body style="margin: '.$margin.'px;">';
if(!isset($_POST['tx']) && !isset($_POST['fx']))
{
echo '
<form method="post" action="'.$_SERVER['PHP_SELF'].'">
<input type="image" src="'.$image.'"><p>';
if(!isset($_POST['x']))
{
echo '
<input type="hidden" name="step" value="2">
click to mark first corner';
}else{
echo '
<input type="hidden" name="step" value="3">
<input type="hidden" name="fx" value="'.$_POST['x'].'">
<input type="hidden" name="fy" value="'.$_POST['y'].'">
click to mark second corner | <a href="'.$_SERVER['PHP_SELF'].'">start over</a>';
}
echo '
</form>
';
}
if(isset($_POST['fx']))
{
echo '
<form method="post" action="'.$_SERVER['PHP_SELF'].'">
<input type="hidden" name="step" value="4">
<input type="image" src="'.$image.'">
<input type="hidden" name="tx" value="'.$_POST['fx'].'">
<input type="hidden" name="ty" value="'.$_POST['fy'].'">
<input type="hidden" name="width" value="'.($_POST['x']-$_POST['fx']).'">
<input type="hidden" name="height" value="'.($_POST['y']-$_POST['fy']).'"><p>
<div style="position: absolute;
left:'.($_POST['fx']+$margin).'px;
top: '.($_POST['fy']+$margin).'px;
width: '.($_POST['x']-$_POST['fx']).'px;
height: '.($_POST['y']-$_POST['fy']).'px;
border: 1px solid #fff;">
</div>
click image to crop rectangle | <a href="'.$_SERVER['PHP_SELF'].'">start over</a>
</form>';
}
if(isset($_POST['tx']))
{
$img = imagecreatetruecolor($_POST['width'],$_POST['height']);
$org_img = imagecreatefromjpeg($image);
$ims = getimagesize($image);
imagecopy($img,$org_img, 0, 0, $_POST['tx'], $_POST['ty'], $ims[0], $ims[1]);
imagejpeg($img,$dest_image,90);
imagedestroy($img);
echo '
<img src="'.$dest_image.'" width="'.$_POST['width'].'" height="'.$_POST['height'].'"><p>
<a href="'.$_SERVER['PHP_SELF'].'">try again</a>';
}
echo '
</body>
</html>';
?>