Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
83 lines (66 loc) · 2.23 KB
/
Copy pathindex.php
File metadata and controls
83 lines (66 loc) · 2.23 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
<?php
require 'vendor/autoload.php';
require_once __DIR__ . '/Constants.php';
require_once BASE_DIR . '/Errors.php';
require_once BASE_DIR . '/FindCircles.php';
$app = new \Slim\Slim();
$app->get('/', function () {
include 'home.php';
});
$app->get('/(env/:env/)find-circles/?(/in/:whatImage/?)' .
'(/min-radius/:minRadius/?)' .
'(/max-radius/:maxRadius/?)' .
'(/sensitivity/:sensitivity/?)', function (
$env = null,
$whatImage = null,
$minRadius = null,
$maxRadius = null,
$sensitivity = null) {
try {
$findCircles = new FindCircles(
$env, $whatImage, $minRadius, $maxRadius, $sensitivity);
print $findCircles->execute();
} catch (Exception $e) {
printError($e->getMessage());
}
});
$app->post('/find-circles/?', function () use ($app) {
$vars = $app->request->post();
$env = isset($vars['env']) ? $vars['env'] : null;
$whatImage = isset($vars['whatImage']) ? $vars['whatImage'] : null;
$minRadius = isset($vars['minRadius']) ? $vars['minRadius'] : null;
$maxRadius = isset($vars['maxRadius']) ? $vars['maxRadius'] : null;
$sensitivity = isset($vars['sensitivity']) ? $vars['sensitivity'] : null;
$image64 = isset($vars['image64']) ? $vars['image64'] : null;
try {
$findCircles = new FindCircles(
$env, $whatImage, $minRadius, $maxRadius, $sensitivity, $image64);
print $findCircles->execute();
} catch (Exception $e) {
printError($e->getMessage());
}
});
$app->get('/inputs/default/?', function () use ($app) {
showImage($app, DEFAULT_IMAGE_PATH);
});
$app->get('/inputs/last/?', function () use ($app) {
showImage($app, LAST_IMAGE_PATH);
});
$app->get('/results/default/?', function () use ($app) {
showImage($app, DEFAULT_IMAGE_RESULT_PATH);
});
$app->get('/results/last/?', function () use ($app) {
showImage($app, LAST_IMAGE_RESULT_PATH);
});
$app->run();
function showImage($app, $path) {
$image = file_get_contents($path);
$app->response->header('Content-Type', 'content-type: image/jpeg');
print $image;
}
function printError($errorMsg) {
$res["status"] = "error";
$res["message"] = $errorMsg;
print json_encode($res);
exit;
}