forked from minotar/imgd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
127 lines (93 loc) · 3.66 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
require 'vendor/autoload.php';
require 'minotar/Minotar.php';
respond('/', function ($request, $response) {
$response->layout('html/template/default.php');
$response->render('html/home.php');
});
respond('/tests', function ($request, $response) {
$response->layout('html/template/default.php');
$response->render('html/tests.php');
});
addValidator('username', function ($str) {
return preg_match('/^[a-z0-9_-]+$/i', $str);
});
respond('/[avatar|head]/[:username].[:format]?/[:size]?.[:formate]?', function ($request, $response) {
$request->validate('username')->isUsername();
$name = $request->param('username', 'char');
$size = $request->param('size', 180);
$ext = $request->param('format', 'png');
$ext = $request->param('formate', 'png');
list($name) = explode('.', $name);
list($size) = explode('.', $size);
$size = min(1000, max(16, (int)$size));
$skin = Minotar::load($name);
$head = Minotar::head($skin);
$img = $head->resize($size);
$img->output($ext);
});
respond('/helm/[:username].[:format]?/[:size]?.[:formate]?', function ($request, $response) {
$request->validate('username')->isUsername();
$name = $request->param('username', 'char');
$size = $request->param('size', 180);
$ext = $request->param('format', 'png');
$ext = $request->param('formate', 'png');
list($name) = explode('.', $name);
list($size) = explode('.', $size);
$size = min(1000, max(16, (int)$size));
$skin = Minotar::load($name);
$helm = Minotar::helm($skin);
$helm->resize($size)->output($ext);
});
respond('/[player|body]/[:username].[:format]?/[:size]?.[:formate]?', function ($request, $response) {
$request->validate('username')->isUsername();
$name = $request->param('username', 'char');
$size = $request->param('size', 180);
$ext = $request->param('format', 'png');
$ext = $request->param('formate', 'png');
list($name) = explode('.', $name);
list($size) = explode('.', $size);
$size = min(1000, max(16, (int)$size));
$skin = Minotar::load($name);
$skin->output($ext);
});
respond('/random/[:size]?.[:format]?', function ($request, $response) {
$size = $request->param('size', 180);
$ext = $request->param('format', 'png');
list($size) = explode('.', $size);
$size = min(1000, max(16, (int)$size));
// We're phasing this out, load me :D
$skin = Minotar::load('clone1018');
$head = Minotar::head($skin);
$img = $head->resize($size);
$img->output($ext);
});
respond('/download/[:username]', function ($request, $response) {
$request->validate('username')->isUsername();
$name = $request->param('username', 'char');
$skin = Minotar::get($name);
header('Content-Disposition: attachment; filename="' . $name . '.png"');
$skin->output('.png');
});
respond('/skin/[:username]', function ($request, $response) {
$request->validate('username')->isUsername();
$name = $request->param('username', 'char');
$skin = Minotar::load($name);
$skin->output('png');
});
respond('/wallpaper/[:width]/[:height]?', function ($request, $response) {
$width = $request->param('width', 1024);
$height = $request->param('height', 768);
// In development
});
respond('/refresh/[:username]', function ($request, $response) {
$request->validate('username')->isUsername();
$username = $request->param('username');
$name = Minotar::delete($username);
//Header("Location: /avatar/$username");
});
respond('404', function ($request, $response) {
$response->layout('html/template/default.php');
$response->render('html/404.php', array("title" => "404"));
});
dispatch();