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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Flask Camera App</title>
|
| 7 |
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
| 9 |
+
<style>
|
| 10 |
+
body {
|
| 11 |
+
font-family: Arial, sans-serif;
|
| 12 |
+
background-color: #f4f4f4;
|
| 13 |
+
margin: 0;
|
| 14 |
+
padding: 0;
|
| 15 |
+
}
|
| 16 |
+
.container {
|
| 17 |
+
max-width: 800px;
|
| 18 |
+
margin: 50px auto;
|
| 19 |
+
text-align: center;
|
| 20 |
+
position: relative; /* Ensure container works with absolute positioning of back button */
|
| 21 |
+
}
|
| 22 |
+
h1 {
|
| 23 |
+
color: #333;
|
| 24 |
+
}
|
| 25 |
+
.btn {
|
| 26 |
+
background-color: #007bff;
|
| 27 |
+
color: white;
|
| 28 |
+
padding: 10px 20px;
|
| 29 |
+
border: none;
|
| 30 |
+
border-radius: 5px;
|
| 31 |
+
cursor: pointer;
|
| 32 |
+
margin: 10px;
|
| 33 |
+
}
|
| 34 |
+
.btn:hover {
|
| 35 |
+
background-color: #0056b3;
|
| 36 |
+
}
|
| 37 |
+
#videoElement {
|
| 38 |
+
width: 100%;
|
| 39 |
+
max-width: 600px;
|
| 40 |
+
margin: 20px 0;
|
| 41 |
+
}
|
| 42 |
+
#cameraSelect {
|
| 43 |
+
padding: 5px;
|
| 44 |
+
margin: 10px;
|
| 45 |
+
}
|
| 46 |
+
#capturedImage {
|
| 47 |
+
margin-top: 20px;
|
| 48 |
+
}
|
| 49 |
+
#hfResult {
|
| 50 |
+
text-align: left;
|
| 51 |
+
background: #fff;
|
| 52 |
+
padding: 10px;
|
| 53 |
+
border-radius: 5px;
|
| 54 |
+
margin-top: 20px;
|
| 55 |
+
max-height: 300px;
|
| 56 |
+
overflow-y: auto;
|
| 57 |
+
}
|
| 58 |
+
/* Green Back Button styling */
|
| 59 |
+
.back-button {
|
| 60 |
+
position: absolute;
|
| 61 |
+
top: 35px;
|
| 62 |
+
left: 15px;
|
| 63 |
+
display: inline-block;
|
| 64 |
+
background-color: green;
|
| 65 |
+
color: white;
|
| 66 |
+
padding: 10px 20px;
|
| 67 |
+
text-decoration: none;
|
| 68 |
+
font-weight: bold;
|
| 69 |
+
border-radius: 4px;
|
| 70 |
+
z-index: 10;
|
| 71 |
+
}
|
| 72 |
+
.back-button:hover {
|
| 73 |
+
background-color: darkgreen;
|
| 74 |
+
}
|
| 75 |
+
</style>
|
| 76 |
+
</head>
|
| 77 |
+
<body>
|
| 78 |
+
<div class="container">
|
| 79 |
+
<a href="{{ url_for('menu.menu') }}" class="back-button"><i class="fa fa-arrow-left"></i></a>
|
| 80 |
+
<h1>Camera Capture App</h1>
|
| 81 |
+
<button id="openCamera" class="btn">Open Camera</button>
|
| 82 |
+
<div id="cameraContainer" style="display: none;">
|
| 83 |
+
<select id="cameraSelect">
|
| 84 |
+
<option value="user">Front Camera</option>
|
| 85 |
+
<option value="environment">Back Camera</option>
|
| 86 |
+
</select>
|
| 87 |
+
<video id="videoElement" autoplay playsinline></video>
|
| 88 |
+
<button id="captureButton" class="btn">Capture Image</button>
|
| 89 |
+
</div>
|
| 90 |
+
<canvas id="canvas" style="display: none;"></canvas>
|
| 91 |
+
<div id="result">
|
| 92 |
+
<img id="capturedImage" style="display: none; max-width: 100%;">
|
| 93 |
+
<div id="actionButtons" style="display: none; margin-top: 10px;">
|
| 94 |
+
<button id="retakeButton" class="btn">Retake</button>
|
| 95 |
+
<button id="uploadButton" class="btn">Upload to Instagram</button>
|
| 96 |
+
</div>
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
<script>
|
| 100 |
+
$(document).ready(function() {
|
| 101 |
+
const video = document.getElementById('videoElement');
|
| 102 |
+
const canvas = document.getElementById('canvas');
|
| 103 |
+
const capturedImage = document.getElementById('capturedImage');
|
| 104 |
+
const cameraSelect = document.getElementById('cameraSelect');
|
| 105 |
+
const actionButtons = document.getElementById('actionButtons');
|
| 106 |
+
let stream = null;
|
| 107 |
+
let currentImageUrl = null;
|
| 108 |
+
// Open camera
|
| 109 |
+
$('#openCamera').click(function() {
|
| 110 |
+
$('#cameraContainer').show();
|
| 111 |
+
actionButtons.style.display = 'none';
|
| 112 |
+
capturedImage.style.display = 'none';
|
| 113 |
+
startCamera(cameraSelect.value);
|
| 114 |
+
});
|
| 115 |
+
// Switch camera
|
| 116 |
+
cameraSelect.addEventListener('change', function() {
|
| 117 |
+
if (stream) {
|
| 118 |
+
stopCamera();
|
| 119 |
+
startCamera(this.value);
|
| 120 |
+
}
|
| 121 |
+
});
|
| 122 |
+
// Capture image
|
| 123 |
+
$('#captureButton').click(function() {
|
| 124 |
+
canvas.width = video.videoWidth;
|
| 125 |
+
canvas.height = video.videoHeight;
|
| 126 |
+
canvas.getContext('2d').drawImage(video, 0, 0);
|
| 127 |
+
const dataUrl = canvas.toDataURL('image/jpeg');
|
| 128 |
+
// Send to server
|
| 129 |
+
$.ajax({
|
| 130 |
+
type: 'POST',
|
| 131 |
+
url: '/capture',
|
| 132 |
+
data: { image: dataUrl },
|
| 133 |
+
success: function(response) {
|
| 134 |
+
if (response.status === 'success') {
|
| 135 |
+
capturedImage.src = response.image_url;
|
| 136 |
+
capturedImage.style.display = 'block';
|
| 137 |
+
actionButtons.style.display = 'block';
|
| 138 |
+
currentImageUrl = response.image_url;
|
| 139 |
+
stopCamera();
|
| 140 |
+
$('#cameraContainer').hide();
|
| 141 |
+
} else {
|
| 142 |
+
alert('Error: ' + response.message);
|
| 143 |
+
}
|
| 144 |
+
},
|
| 145 |
+
error: function() {
|
| 146 |
+
alert('Failed to capture image.');
|
| 147 |
+
}
|
| 148 |
+
});
|
| 149 |
+
});
|
| 150 |
+
// Retake button
|
| 151 |
+
$('#retakeButton').click(function() {
|
| 152 |
+
$('#cameraContainer').show();
|
| 153 |
+
actionButtons.style.display = 'none';
|
| 154 |
+
capturedImage.style.display = 'none';
|
| 155 |
+
startCamera(cameraSelect.value);
|
| 156 |
+
});
|
| 157 |
+
// Upload to Zapier
|
| 158 |
+
$('#uploadButton').click(function() {
|
| 159 |
+
if (!currentImageUrl) {
|
| 160 |
+
alert('No image to upload.');
|
| 161 |
+
return;
|
| 162 |
+
}
|
| 163 |
+
$.ajax({
|
| 164 |
+
type: 'POST',
|
| 165 |
+
url: '/upload_zapier',
|
| 166 |
+
data: { image_url: currentImageUrl },
|
| 167 |
+
success: function(response) {
|
| 168 |
+
if (response.status === 'success') {
|
| 169 |
+
alert('Image sent to Zapier successfully!');
|
| 170 |
+
actionButtons.style.display = 'none';
|
| 171 |
+
capturedImage.style.display = 'none';
|
| 172 |
+
} else {
|
| 173 |
+
alert('Error sending to Zapier: ' + response.message);
|
| 174 |
+
}
|
| 175 |
+
},
|
| 176 |
+
error: function() {
|
| 177 |
+
alert('Failed to send image to Zapier.');
|
| 178 |
+
}
|
| 179 |
+
});
|
| 180 |
+
});
|
| 181 |
+
function startCamera(facingMode) {
|
| 182 |
+
const constraints = {
|
| 183 |
+
video: { facingMode: facingMode }
|
| 184 |
+
};
|
| 185 |
+
navigator.mediaDevices.getUserMedia(constraints)
|
| 186 |
+
.then(function(mediaStream) {
|
| 187 |
+
stream = mediaStream;
|
| 188 |
+
video.srcObject = stream;
|
| 189 |
+
})
|
| 190 |
+
.catch(function(err) {
|
| 191 |
+
alert('Error accessing camera: ' + err.message);
|
| 192 |
+
});
|
| 193 |
+
}
|
| 194 |
+
function stopCamera() {
|
| 195 |
+
if (stream) {
|
| 196 |
+
stream.getTracks().forEach(track => track.stop());
|
| 197 |
+
stream = null;
|
| 198 |
+
video.srcObject = null;
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
});
|
| 202 |
+
</script>
|
| 203 |
+
</body>
|
| 204 |
+
</html>
|