-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.php
70 lines (57 loc) · 1.84 KB
/
handler.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
<?php
require_once __DIR__ . '/functions.php';
require __DIR__ . '/vendor/autoload.php';
use Cvuorinen\Raspicam\Raspistill;
// Configure camera based on inputs
// values are validated by Raspistill
$params = array();
// all params are handled with a std procedure....
foreach (PARAMETERS as $key => $value) {
// ... except those requiring custom input handler
if (empty($value['customInputHandler'])) {
if (isset($_REQUEST[$value['name']])) {
if ($value['type'] == 'numeric') {
$params[$value['name']] = intval($_REQUEST[$value['name']]);
}
else
$params[$value['name']] = $_REQUEST[$value['name']];
}
}
}
// parameter with custom input handler
if (isset($_REQUEST['flip']) && !empty($_REQUEST['flip'])) {
if ($_REQUEST['flip']=="hflip") {
$params['horizontalFlip'] = true;
}
else if ($_REQUEST['flip']=="vflip") {
$params['verticalFlip'] = true;
}
else if ($_REQUEST['flip']=="hvflip") {
$params['horizontalFlip'] = true;
$params['verticalFlip'] = true;
}
}
// fixed parameters
$params['encoding'] = 'jpg';
$params['timeout'] = 0.001;
$params['quality'] = 65;
$params['sensorMode'] = 6;
$response = array();
try {
$folder = '/pictures';
$phisical_path = __DIR__ . $folder;
if (!file_exists($phisical_path)) {
if (!mkdir($phisical_path))
throw new Exception("Unable to create $phisical_path folder. Check permissions.");
}
$picture = mktime().".jpg";
$camera = new Raspistill($params);
$camera->takePicture($phisical_path . '/' . $picture);
$response['status'] = 'ok';
$response['picture'] = '.' . $folder . '/' . $picture;
} catch (Exception $ex) {
$response['status'] = 'fail';
$response['error'] = $ex->getMessage();
}
header('Content-type: application/json');
echo json_encode($response);