-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_snap.php
90 lines (85 loc) · 2.7 KB
/
save_snap.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
<?php
session_start();
function add_image_to_table($img_nom, $img_taille, $img_type, $user_login)
{
require 'config/setup.php';
try
{
$stmt = $db_con->prepare("INSERT INTO images(img_nom,img_taille,img_type,user_login) VALUES(:img_nom, :img_taille, :img_type, :user_login)");
$val = $stmt->execute(array(":img_nom"=>$img_nom, ":img_taille"=>$img_taille,":img_type"=>$img_type,":user_login"=>$user_login));
if($val)
$_SESSION['error'] = 'Upload effectué avec succès !';
else
$_SESSION['error'] = 'Echec de l\'upload !';
}
catch(PDOException $e){
echo $e->getMessage();
}
}
function get_img_name($int)
{
require 'config/setup.php';
$name = "new_image_";
try
{
$stmt = $db_con->prepare("SELECT * FROM images");
$stmt->execute();
$count = $stmt->rowCount() + $int;
$name = $name.$count.".png";
}
catch(PDOException $e){
echo $e->getMessage();
}
try
{
$stmt = $db_con->prepare("SELECT * FROM images WHERE img_nom=:img_nom");
$stmt->execute(array(":img_nom"=>$name));
$count = $stmt->rowCount();
if ($count != 0)
return(get_img_name($int + 1));
}
catch(PDOException $e){
echo $e->getMessage();
}
return($name);
}
function add_filter($filtre, $name)
{
header("Content-type: image/png");
$largeur = 640;
$hauteur = 480;
$rendu = imagecreatetruecolor($largeur, $hauteur);
$fond = imagecolorallocatealpha($rendu, 0, 128, 255, 0);
imagefill($rendu, 0, 0, $fond);
$image1 = imagecreatefrompng("img_gallery/".$name);
if ($filtre === "licornes")
$image2 = imagecreatefrompng("imgs/cadre_licorne.png");
else if ($filtre === "masque")
$image2 = imagecreatefrompng("imgs/masque_paul.png");
else if ($filtre === "chat")
$image2 = imagecreatefrompng("imgs/cadre_chaton.png");
else if ($filtre === "marron")
$image2 = imagecreatefrompng("imgs/blue_filtre.png");
imagecopy($rendu, $image1, 0, 0, 0,0, $largeur, $hauteur);
imagecopy($rendu, $image2, 0, 0, 0,0, 640, 480);
imagesavealpha($rendu, true);
imagepng($rendu, "img_gallery/".$name);
}
$img = $_POST['img'];
$filtre = $_POST['filtre'];
$name = get_img_name(0);
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = $upload_dir."img_gallery/".$name;
add_image_to_table($name, 1, "png", $_SESSION['login']);
$success = file_put_contents($file, $data);
if ($filtre != "")
add_filter($filtre, $name);
else
{
}
if (file_exists ("tmp_img/img_tmp.png"))
unlink ("tmp_img/img_tmp.png");
echo $file;
?>