-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
68 lines (54 loc) · 1.63 KB
/
index.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
<?php
require_once "./vendor/autoload.php";
use App\Utils;
use Phroute\Phroute\RouteCollector;
use Phroute\Phroute\Dispatcher;
use Intervention\Image\ImageManager;
$collector = new RouteCollector();
$collector->get('/', function () {
require_once "index.view.php";
});
function useUtils()
{
return new Utils\Utils();
}
$collector->get('/{t}/{w}/{h}', function ($t, $w, $h) {
//create instance of image manager and use image magick for driver
if ($w > 2000 || $h > 2000) {
$w = 2000;
$h = 2000;
}
$img = new ImageManager(array('driver' => 'imagick'));
$path = useUtils()->genPic($t);
$response = $img->make($path)->fit($w, $h)->response("jpg", 60);
unset($path);
return $response;
});
$collector->get('/stats', function () {
return useUtils()->updateStats();
});
$collector->get('/homepage', function () {
return json_encode(
array(
"dirName" => useUtils()->getDirNames(),
"imageCount" => useUtils()->getImageTotal()
)
);
});
$collector->get('/data', function () {
return json_encode(
array(
"dirName" => useUtils()->getDirData(),
"totalImages" => useUtils()->getImageTotal(),
"totalUsage" => useUtils()->readStats()->count,
"debug" => useUtils()->getDebug()
)
);
});
$collector->get('/dirs', function () {
return json_encode(useUtils()->getDirNames());
});
$dispatcher = new Dispatcher($collector->getData());
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
echo $response;
//echo json_encode($path);