-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
49 lines (39 loc) · 1.18 KB
/
upload.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
<?php
include 'include/context.php';
$fn = $_FILES['imageUpload']['tmp_name'];
$max = 640;
list($width, $height, $type, $attr) = getimagesize($fn);
$exif = exif_read_data($fn);
$src = imagecreatefromstring(file_get_contents($fn));
$dst = imagecreatetruecolor($max, $max);
if ($width > $height) {
$x_point = ($width - $height) / 2;
imagecopyresampled($dst, $src, 0, 0, $x_point, 0, $max, $max, $height, $height);
} else {
$y_point = ($height - $width) / 2;
imagecopyresampled($dst, $src, 0, 0, 0, $y_point, $max, $max, $width, $width);
}
if (isset($exif['Orientation'])) {
$orientation = $exif['Orientation'];
} else {
$orientation = 0;
}
if ($orientation == 3) {
$dst = imagerotate($dst, 180, 0);
}
if ($orientation == 6) {
$dst = imagerotate($dst, 270, 0);
}
if ($orientation == 8) {
$dst = imagerotate($dst, 90, 0);
}
if (isset($exif['DateTimeOriginal'])) {
$target = $storage . strtotime($exif['DateTimeOriginal']) . '.jpeg';
} else {
$target = $storage . time() . '.jpeg';
}
imagejpeg($dst, $target);
imagedestroy($src);
imagedestroy($dst);
redirect();
?>