forked from minotar/imgd
/
index.php
117 lines (93 loc) · 3.7 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
<?php require 'klein.php';
include 'WideImage/WideImage.php';
include 'Minotar.php';
error_reporting(0);
respond('/', function ($request, $response) {
$response->render('html/home.phtml');
});
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(1, (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(1, (int) $size));
$name = Minotar::get($name);
$img = WideImage::load("./minecraft/helms/$name.png")->resize($size);
$img->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(1, (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(1, (int) $size));
$avatars = scandir('./minecraft/heads/');
$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/[:type]?', function ($request, $response) {
$type = $request->param('type', 'heads');
$files = Minotar::getFilesFromDir("./minecraft/$type");
$response->render('html/all.phtml', array('files' => $files));
});
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);
});
dispatch();