forked from minotar/imgd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
167 lines (131 loc) · 5.47 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
require 'klein.php';
include 'WideImage/WideImage.php';
include 'Minotar.php';
define('URL', 'https://minotar.net/');
//error_reporting(0);
respond('/', function ($request, $response) {
$response->layout('html/template/default.php');
$response->render('html/home.php');
});
respond('/[avatar|head]/[:username].[:format]?/[:size]?.[:formate]?', function ($request, $response) {
$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));
$name = Minotar::get($name);
$img = WideImage::load("./minecraft/heads/$name.png")->resize($size);
$img->output($ext);
});
respond('/helm/[:username].[:format]?/[:size]?.[:formate]?', function ($request, $response) {
$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));
$name = Minotar::get($name);
$head = WideImage::load("./minecraft/heads/$name.png");
$helm = WideImage::load("./minecraft/helms/$name.png");
for ($x = 0; $x < $helm->getWidth(); $x++) {
for ($y = 0; $y < $helm->getHeight(); $y++) {
$color = $helm->getColorAt($x, $y);
if($color == PHP_INT_MAX || $color == 0 || $color == (256*256*256*127))
$pixels++;
}
}
if($pixels == $head->getWidth() * $head->getHeight())
$result = clone $head;
else
$result = $head->merge($helm);
$result->resize($size)->output($ext);
});
respond('/[player|body]/[:username].[:format]?/[:size]?.[:formate]?', function ($request, $response) {
$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));
$name = Minotar::get($name);
$img = WideImage::load("./minecraft/players/$name.png")->resize($size);
$img->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));
$avatars = array_diff(scandir('./minecraft/heads/'), array('..', '.', '.gitignore'));
$rand = array_rand($avatars);
$avatar = $avatars[$rand];
$name = str_replace('.png', '', $avatar);
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
WideImage::load("./minecraft/heads/$name.png")->resize($size)->output('png');
});
respond('/download/[:username]', function ($request, $response) {
$name = $request->param('username', 'char');
$name = Minotar::get($name);
$img = WideImage::load("./minecraft/skins/$name.png");
header('Content-Disposition: attachment; filename="' . $name . '.png"');
$img->output('.png');
});
respond('/skin/[:username]', function ($request, $response) {
$name = $request->param('username', 'char');
$name = Minotar::get($name);
$img = WideImage::load("./minecraft/skins/$name.png");
$img->output('.png');
});
respond('/all/[head|helm|skin:type]/[i:start]?', function ($request, $response) {
$type = $request->param('type', 'head');
$start = $request->param('start', 0);
$limit = 85;
$files = Minotar::getFilesFromDir("./minecraft/{$type}s");
$response->layout('html/template/default.php');
foreach(array_slice($files, $start, $limit) as $file) {
$segments = explode("/", $file);
$dir_list = array_values((explode(".", end($segments))));
$file_list[] = array_shift($dir_list);
}
if($files) {
$response->render('html/all.php', array('files' => $file_list, 'type' => $type, 'start' => $start, 'limit' => $limit, 'total' => count($files), 'title' => "All {$type}s"));
return;
}
$response->render('html/404.php', array("title" => "404"));
});
respond('/wallpaper/[:width]/[:height]?', function ($request, $response) {
$width = $request->param('width', 1024);
$height = $request->param('height', 768);
$files = Minotar::getFilesFromDir("./minecraft/heads");
if ($width >= 1920)
$width = 1920;
if ($height >= 1080)
$height = 1080;
$files = array_slice($files, 500);
//list($width, $height) = getimagesize($_GET['image']);
$image_p = imagecreatetruecolor($width, $height);
$count = 1;
foreach ($files as $avatar) {
$image = imagecreatefrompng($avatar);
imagecopyresampled($image_p, $image, $width * $count, $height * $count, 0, 0, $width, $height, 42, 42);
$count++;
}
header('Content-type: image/png');
imagejpeg($image_p, null, 100);
});
respond('/refresh/[:username]', function ($request, $response) {
$username = $request->param('username');
$name = Minotar::get($username, true);
Header("Location: ".URL."avatar/$username");
});
respond('404', function ($request, $response) {
$response->layout('html/template/default.php');
$response->render('html/404.php', array("title" => "404"));
});
dispatch();