-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg_mix.php
99 lines (86 loc) · 2.71 KB
/
img_mix.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
session_start();
include_once('config/database.php');
if (($_FILES['uppic']['error'] == UPLOAD_ERR_FORM_SIZE)) {
$_SESSION['alert'] = "LA TAILLE DU FICHIER DE VOTRE PHOTO EST TROP GRANDE (MAX. 1MO)";
unset($_FILES['uppic']);
header('Location: index.php');
return;
}
if ($_FILES['uppic']['error'] > 0) {
$_SESSION['alert'] = "UNE ERREUR EST SURVENUE LORS DU TRANSFERT DE VOTRE PHOTO";
unset($_FILES['uppic']);
header('Location: index.php');
return;
}
if ($_FILES['uppic']) {
$array = getimagesize($_FILES['uppic']['tmp_name']);
$type = $array[2];
if ($type != 3) {
$_SESSION['alert'] = "VOTRE PHOTO DOIT ÊTRE DE TYPE PNG!";
header('Location: index.php');
return;
}
}
if (!file_exists('gallery/'))
mkdir('gallery/');
$picname = time();
$picpath = 'gallery/' .$picname. '.png';
if ($_POST['img']) {
$img = htmlspecialchars($_POST['img']);
$img = str_replace("data:image/png;base64,", "", $img);
$img = str_replace(" ", "+", $img);
$file = base64_decode($img);
file_put_contents($picpath, $file);
}
else if ($_FILES) {
$transfert = move_uploaded_file($_FILES['uppic']['tmp_name'], $picpath);
if (!$transfert)
$_SESSION['alert'] = "UN PROBLÈME EST SURVENU LORS DU TRANSFERT DE VOTRE PHOTO";
}
$file = imagecreatefrompng($picpath);
$png = htmlspecialchars($_POST['filter']);
$filter = imagecreatefrompng($png);
$widthFile = imagesx($file);
$heightFile = imagesy($file);
$width_filter = imagesx($filter);
$height_filter = imagesy($filter);
$file_x = $widthFile / 2;
$file_y = $heightFile * (10/100);
imagecopy($file, $filter, $file_x, $file_y, 0, 0, $width_filter, $height_filter);
if ($_POST['effect'] != '') {
$effect = htmlspecialchars($_POST['effect']);
if ($effect == "grayscale")
imagefilter($file, IMG_FILTER_GRAYSCALE);
if ($effect == "invert")
imagefilter($file, IMG_FILTER_NEGATE);
if ($effect == "sepia") {
imagefilter($file, IMG_FILTER_GRAYSCALE);
imagefilter($file, IMG_FILTER_COLORIZE, 50, 35, 5);
imagefilter($file, IMG_FILTER_BRIGHTNESS, -30);
}
if ($effect == "blur") {
$i = 0;
while ($i < 40) {
imagefilter($file, IMG_FILTER_GAUSSIAN_BLUR);
$i++;
}
imagefilter($file, IMG_FILTER_BRIGHTNESS, 20);
}
}
if (!file_exists('gallery/'))
mkdir('gallery/');
imagepng($file, $picpath);
try {
$db = new PDO($DB_DSN, $DB_USER, $DB_PASSWORD);
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch(PDOException $e) {
echo $e->getMessage();
}
$req = $db->prepare('INSERT INTO photos(login, user_id, picpath) VALUES (?, ?, ?)');
$req->execute(array($_SESSION['login'], $_SESSION['userid'], $picpath));
$req->closeCursor();
$_SESSION['picpath'] = $picpath;
header("Refresh:0; url=index.php");
?>