-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.php
More file actions
186 lines (171 loc) · 5.97 KB
/
Copy pathcamera.php
File metadata and controls
186 lines (171 loc) · 5.97 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/*ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);*/
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
include './config/createConnection.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>WEBCAM</title>
</head>
<body>
<?php include('header.php') ?>
<br>
<br>
<!--Sticker SAMPLES-->
<div class="stickers" style="height: 30px">
<img src="./resources/blank.png" alt="none" id="img0"/>
<img src="./resources/pig.png" width="1" height="1" alt="pig" id="img1"/>
<img src="./resources/cheese.png" width="1" height="1" alt="cheese" id="img2"/>
<img src="./resources/flame.png" width="1" height="1" alt="flame" id="img4" />
<img src="./resources/splash.png" width="1" height="1" alt="splash" id="img3" />
</div>
<br />
<!--Stream video via webcam-->
<div class="video-wrap">
<video id="video" playsinline autoplay></video>
</div>
<!--Trigger canvas Web API-->
<div class="controller">
<button id="snap">Capture</button>
<button id="save">Save</button>
<button id="clear">Clear</button>
<label>Sticker Left</label>
<select id="mySelect" size="1">
<option selected="selected" value="img0">None</option>
<option value="img1">Peppa Pig</option>
<option value="img2">Cheese</option>
<option value="img3">Splash</option>
<option value="img4">Flame</option>
</select>
<label>Sticker Right</label>
<select id="mySelect2" size="1">
<option selected="selected" value="img0">None</option>
<option value="img1">Peppa Pig</option>
<option value="img2">Cheese</option>
<option value="img3">Splash</option>
<option value="img4">Flame</option>
</select>
<label>Sticker Bottom</label>
<select id="mySelect3" size="1">
<option selected="selected" value="img0">None</option>
<option value="img1">Peppa Pig</option>
<option value="img2">Cheese</option>
<option value="img3">Splash</option>
<option value="img4">Flame</option>
</select>
</div>
<!-- Webcam video snapshot-->
<canvas id="canvas" width="640" height="480"></canvas>
<script>
'use strict';
//var mySticker = "img0";
const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const snap = document.getElementById('snap');
//const reset = document.getElementById('reset');
const errorMsgElement = document.getElementById('spanErrorMsg');
var photo = null;
const constraints = {
audio: false,
video:{
width:640, height: 480
}
};
//Access webcam
async function init(){
try{
const stream = await navigator.mediaDevices.getUserMedia(constraints);
handleSuccess(stream);
}
catch(e){
errorMsgElement.innerHTML = 'navigator.getUserMedia.error:${e.toString()}';
}
}
// Success
function handleSuccess(stream){
window.stream = stream;
video.srcObject = stream;
}
// Load init
init();
//Draw Image
var context = canvas.getContext('2d');
snap.addEventListener("click", function(){
var mySticker = mySticker_function();
var mySticker2 = mySticker_function2();
var mySticker3 = mySticker_function3();
context.drawImage(video, 0, 0, 640, 480);
context.drawImage(document.getElementById(mySticker), 0, 0, 150, 200);
context.drawImage(document.getElementById(mySticker2), 430, 0, 150, 200);
context.drawImage(document.getElementById(mySticker3), 240, 320, 150, 200);
//context.drawImage(, 0, 0, 300, 30);
});
//Reset Image
//var context = canvas.getContext('2d');
document.getElementById('clear').addEventListener('click', function() {
context.clearRect(0, 0, canvas.width, canvas.height);
}, false);
// //Save Image
var save_img = document.getElementById("save");
save.addEventListener("click", ()=>{
var data = canvas.toDataURL();
data = data.replace("data:image/png;base64,","");
var request = new XMLHttpRequest();
request.onload = () => {
console.log(request.responseText, request);
}
request.open("POST","/Camagru/save_img.php");
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send("img=" + encodeURIComponent(data));
window.location.reload();
});
function mySticker_function() {
var x = document.getElementById("mySelect").value;
return x;
}
function mySticker_function2() {
var x = document.getElementById("mySelect2").value;
return x;
}
function mySticker_function3() {
var x = document.getElementById("mySelect3").value;
return x;
}
</script>
<?php
$userid = $_SESSION["id"];
try{
$sql = "SELECT * FROM images WHERE userid = '".$userid."' ORDER BY uploaded_on DESC LIMIT 5";
$stmt = $conn->prepare($sql);
if ($stmt->execute() && $stmt->rowCount() > 0){
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$imageURL = 'images/'.$row["source"];
?>
<br>
<img src="<?php echo $imageURL; ?>" alt="" height="160" width=""/>
<form>
<input type="hidden" name="uid" value="currUser">
<input type="hidden" name="date" value="">
</form>
<?php }
}else{ ?>
<p>No image(s) found...</p>
<?php }
}catch(PDOException $e){
$statusMsg = "Failed to load images, please try again.";
echo $sql . "<br>" . $statusMsg . "<br>" . $e.getMessage();
}
include('footer.php')
?>
</body>
</html>