-
Notifications
You must be signed in to change notification settings - Fork 16
/
service.php
101 lines (80 loc) · 2.67 KB
/
service.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
100
101
<?php
require_once("CameraRaw.php");
//time gphoto2 --quiet --capture-image-and-download --filename "./images/capture-%Y%m%d-%H%M%S-%03n.%C"
//exec ("gphoto2 --set-config uilock=1",$output);
//echo join("\n",$output);
//exec ("gphoto2 --capture-image",$output);
//echo join("\n",$output);
//exec ("gphoto2 --set-config uilock=1",$output);
//echo join("\n",$output);
$action = '';
if (isset($_GET['action'])){
$action = $_GET['action'];
}
$returnObj;
try{
switch($action){
case "takePicture":
exec ("gphoto2 --capture-image-and-download --filename \"./images/capture-%Y%m%d-%H%M%S-%03n.%C\"",$output);
echo json_encode(true);
break;
case "deleteFile":
$file = $_GET['file'];
$path_parts = pathinfo('images/'.$file);
unlink('images/'.$file);
unlink('images/thumbs/'.$path_parts['basename'].'.jpg');
header('Content-Type: application/json');
echo json_encode(true);
break;
case "getImage":
$file = $_GET['file'];
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$file.'"');
header('Content-Length: '.filesize('images/'.$file));
$fp = fopen('images/'.$file, 'rb');
fpassthru($fp);
exit;
break;
case "getCamera":
exec ("gphoto2 --auto-detect", $output);
$returnObj->camera = trim(explode("usb", $output[count($output) - 1])[0]);
header('Content-Type: application/json');
echo json_encode($returnObj);
break;
case "getImages":
$files = array();
$imageDir = opendir('images');
while (($file = readdir($imageDir)) !== false) {
if(!is_dir('images/'.$file)){
$path_parts = pathinfo('images/'.$file);
if (!file_exists('images/thumbs/'.$path_parts['basename'].'.jpg')){
try { //try to extract the preview image from the RAW
CameraRaw::extractPreview('images/'.$file, 'images/thumbs/'.$path_parts['basename'].'.jpg');
} catch (Exception $e) { //else resize the image...
$im = new Imagick('images/'.$file);
$im->setImageFormat('jpg');
$im->scaleImage(1024,0);
$im->writeImage('images/thumbs/'.$path_parts['basename'].'jpg');
$im->clear();
$im->destroy();
}
}
$returnFile;
$returnFile->name = $path_parts['basename'];
$returnFile->sourcePath = 'images/'.$file;
$returnFile->thumbPath = 'images/thumbs/'.$path_parts['basename'].'.jpg';
array_push($files,$returnFile);
unset($returnFile);
}
}
closedir($imageDir);
$returnObj = $files;
header('Content-Type: application/json');
echo json_encode($returnObj);
break;
default:
break;
}
} catch (Exception $e) { //else resize the image...
}
?>