├── .htaccess
├── LICENSE.md
├── README.md
├── composer.json
├── face.php
└── skin.php
/.htaccess:
--------------------------------------------------------------------------------
1 |
2 | Options +FollowSymlinks
3 | Options -MultiViews
4 | RewriteEngine on
5 | IndexIgnore *
6 | RewriteBase /
7 |
8 | RewriteCond %{REQUEST_FILENAME} !-d
9 | RewriteRule ^(.+)/$ $1 [R=301,L]
10 |
11 | RewriteRule ^avatar/([^/]+)/([^/]+)/(f|l|r|b|front|left|right|back)$ face.php?u=$1&s=$2&v=$3
12 | RewriteRule ^avatar/([^/]+)/(f|l|r|b|front|left|right|back)$ face.php?u=$1&v=$2
13 | RewriteRule ^avatar/([^/]+)/([^/]+)$ face.php?u=$1&s=$2
14 | RewriteRule ^avatar/([^/]+)$ face.php?u=$1
15 | RewriteRule ^skin/([^/]+)/([^/]+)$ skin.php?u=$1&s=$2
16 | RewriteRule ^skin/([^/]+)$ skin.php?u=$1
17 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2012-2016 Jamie Bicknell - @jamiebicknell
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Minecraft Avatar
2 |
3 | PHP/GD creation of a Minecraft facial avatar or full skin preview based on a given username, constructed from their Minecraft skin.
4 |
5 | If username is not found, then it uses the default Steve skin: [http://assets.mojang.com/SkinTemplates/steve.png](http://assets.mojang.com/SkinTemplates/steve.png)
6 |
7 | ## Facial Avatar
8 |
9 |
10 |
11 | ```html
12 |
13 | ```
14 |
15 | #### Query Parameters
16 |
17 |
18 |
19 | Key |
20 | Example Value |
21 | Default |
22 | Description |
23 |
24 |
25 | u |
26 | jamiebicknell |
27 | steve |
28 | Username of Minecraft player |
29 |
30 |
31 | s |
32 | 8 - 250 |
33 | 48 |
34 | Desired avatar width and height |
35 |
36 |
37 | v |
38 | f, l, r, b front, left, right, back |
39 | front |
40 | View of facial avatar (optional) |
41 |
42 |
43 |
44 | ## Skin Preview
45 |
46 |
47 |
48 |
49 |
50 | ```html
51 |
52 | ```
53 |
54 | #### Query Parameters
55 |
56 |
57 |
58 | Key |
59 | Example Value |
60 | Default |
61 | Description |
62 |
63 |
64 | u |
65 | jamiebicknell |
66 | steve |
67 | Username of Minecraft player |
68 |
69 |
70 | s |
71 | 40 - 800 |
72 | 250 |
73 | Desired skin preview width |
74 |
75 |
76 |
77 | ## .Htaccess
78 |
79 | If you have `mod_rewrite` enabled you can view the avatar via cleaner URLs.
80 |
81 | #### Facial Avatar
82 |
83 | ```html
84 |
85 | ```
86 |
87 | ```html
88 |
89 | ```
90 |
91 | ```html
92 |
93 | ```
94 |
95 | ```html
96 |
97 | ```
98 |
99 | #### Skin Preview
100 |
101 | ```html
102 |
103 | ```
104 |
105 | ```html
106 |
107 | ```
108 |
109 | ## Notes
110 |
111 | * After changing your skin on [Minecraft.net](https://minecraft.net/profile) it can take up to 1 hour for the facial avatar or skin preview to show the new skin.
112 | * The skin preview differenciates between the Steve (4 pixel arm width) and Alex skin (3 pixel arm width) by checking the alpha value on the pixel at 54, 20. Therefore, the preview assumes that the skin is well formed and that the unallocated areas are transparent.
113 | * Default skins: [Steve](http://assets.mojang.com/SkinTemplates/steve.png) and [Alex](http://assets.mojang.com/SkinTemplates/alex.png)
114 | * Skin templates: [Steve](http://assets.mojang.com/SkinTemplates/4px_reference.png) and [Alex](http://assets.mojang.com/SkinTemplates/3px_reference.png)
115 |
116 | ## License
117 |
118 | Minecraft Avatar is licensed under the [MIT license](http://opensource.org/licenses/MIT), see [LICENSE.md](https://github.com/jamiebicknell/Minecraft-Avatar/blob/master/LICENSE.md) for details.
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jamiebicknell/Minecraft-Avatar",
3 | "description": "PHP/GD creation of a Minecraft facial avatar or full skin preview based on a given username, constructed from their Minecraft skin",
4 | "keywords": [
5 | "minecraft",
6 | "avatar",
7 | "skin",
8 | "php",
9 | "gd"
10 | ],
11 | "homepage": "http://github.com/jamiebicknell/Minecraft-Avatar",
12 | "license": "MIT",
13 | "authors": [
14 | {
15 | "name": "Jamie Bicknell",
16 | "homepage": "http://www.jamiebicknell.com"
17 | }
18 | ],
19 | "require": {
20 | "php": ">=5.2.0"
21 | }
22 | }
--------------------------------------------------------------------------------
/face.php:
--------------------------------------------------------------------------------
1 | 8, 'l' => 16, 'r' => 0, 'b' => 24);
70 |
71 | imagecopyresized($av, $im, 0, 0, $x[$view], 8, $size, $size, 8, 8); // Face
72 | imagecolortransparent($im, imagecolorat($im, 63, 0)); // Black Hat Issue
73 | imagecopyresized($av, $im, 0, 0, $x[$view] + 32, 8, $size, $size, 8, 8); // Accessories
74 |
75 | header('Content-type: image/png');
76 | imagepng($av);
77 | imagedestroy($im);
78 | imagedestroy($av);
79 |
--------------------------------------------------------------------------------
/skin.php:
--------------------------------------------------------------------------------
1 | 32) {
76 | // 1.8+ Skin
77 | if ((imagecolorat($im, 54, 20) >> 24) & 0x7F == 127) {
78 | // Alex Style Skin (3px Arm Width)
79 | // Front
80 | imagecopyresized($av, $im, $p + $s * 4, $p, 8, 8, $s * 8, $s * 8, 8, 8);
81 | imagecopyresized($av, $im, $p + $s * 4, $p + $s * 8, 20, 20, $s * 8, $s * 12, 8, 12);
82 | imagecopyresized($av, $im, $p + $s * 1, $p + $s * 8, 44, 20, $s * 3, $s * 12, 3, 12);
83 | imagecopyresized($av, $im, $p + $s * 12, $p + $s * 8, 36, 52, $s * 3, $s * 12, 3, 12);
84 | imagecopyresized($av, $im, $p + $s * 4, $p + $s * 8 + $s * 12, 4, 20, $s * 4, $s * 12, 4, 12);
85 | imagecopyresized($av, $im, $p + $s * 8, $p + $s * 8 + $s * 12, 20, 52, $s * 4, $s * 12, 4, 12);
86 |
87 | // Right
88 | imagecopyresized($av, $im, $p + $s * $g + $s * 16, $p, 0, 8, $s * 8, $s * 8, 8, 8);
89 | imagecopyresized($av, $im, $p + $s * $g + $s * 18, $p + $s * 8, 40, 20, $s * 4, $s * 12, 4, 12);
90 | imagecopyresized($av, $im, $p + $s * $g + $s * 18, $p + $s * 8 + $s * 12, 0, 20, $s * 4, $s * 12, 4, 12);
91 |
92 | // Back
93 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p, 24, 8, $s * 8, $s * 8, 8, 8);
94 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p + $s * 8, 32, 20, $s * 8, $s * 12, 8, 12);
95 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 25, $p + $s * 8, 43, 52, $s * 3, $s * 12, 3, 12);
96 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 36, $p + $s * 8, 51, 20, $s * 3, $s * 12, 3, 12);
97 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p + $s * 8 + $s * 12, 28, 52, $s * 4, $s * 12, 4, 12);
98 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 32, $p + $s * 8 + $s * 12, 12, 20, $s * 4, $s * 12, 4, 12);
99 |
100 | // Left
101 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 40, $p, 16, 8, $s * 8, $s * 8, 8, 8);
102 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 42, $p + $s * 8, 39, 52, $s * 4, $s * 12, 4, 12);
103 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 42, $p + $s * 8 +$s * 12, 24, 52, $s * 4, $s * 12, 4, 12);
104 |
105 | // Black Hat Issue
106 | imagecolortransparent($im, imagecolorat($im, 63, 0));
107 |
108 | // Face Accessories
109 | imagecopyresized($av, $im, $p + $s * 4, $p, 40, 8, $s * 8, $s * 8, 8, 8);
110 | imagecopyresized($av, $im, $p + $s * $g + $s * 16, $p, 32, 8, $s * 8, $s * 8, 8, 8);
111 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p, 56, 8, $s * 8, $s * 8, 8, 8);
112 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 40, $p, 48, 8, $s * 8, $s * 8, 8, 8);
113 |
114 | // Body Accessories
115 | imagecopyresized($av, $im, $p + $s * 4, $p + $s * 8, 20, 36, $s * 8, $s * 12, 8, 12);
116 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p + $s * 8, 32, 36, $s * 8, $s * 12, 8, 12);
117 |
118 | // Arm Accessores
119 | imagecopyresized($av, $im, $p + $s * 1, $p + $s * 8, 44, 36, $s * 3, $s * 12, 3, 12);
120 | imagecopyresized($av, $im, $p + $s * 12, $p + $s * 8, 52, 52, $s * 3, $s * 12, 3, 12);
121 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 25, $p + $s * 8, 59, 52, $s * 3, $s * 12, 3, 12);
122 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 36, $p + $s * 8, 51, 36, $s * 3, $s * 12, 3, 12);
123 | imagecopyresized($av, $im, $p + $s * $g + $s * 18, $p + $s * 8, 40, 36, $s * 4, $s * 12, 4, 12);
124 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 42, $p + $s * 8, 55, 52, $s * 4, $s * 12, 4, 12);
125 |
126 | // Leg Accessores
127 | imagecopyresized($av, $im, $p + $s * 4, $p + $s * 8 + $s * 12, 4, 36, $s * 4, $s * 12, 4, 12);
128 | imagecopyresized($av, $im, $p + $s * 8, $p + $s * 8 + $s * 12, 4, 52, $s * 4, $s * 12, 4, 12);
129 | imagecopyresized($av, $im, $p + $s * $g + $s * 18, $p + $s * 8 + $s * 12, 0, 36, $s * 4, $s * 12, 4, 12);
130 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p + $s * 8 + $s * 12, 12, 52, $s * 4, $s * 12, 4, 12);
131 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 32, $p + $s * 8 + $s * 12, 12, 36, $s * 4, $s * 12, 4, 12);
132 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 42, $p + $s * 8 +$s * 12, 8, 52, $s * 4, $s * 12, 4, 12);
133 | } else {
134 | // Steve Style Skin (4px Arm Width)
135 | // Front
136 | imagecopyresized($av, $im, $p + $s * 4, $p, 8, 8, $s * 8, $s * 8, 8, 8);
137 | imagecopyresized($av, $im, $p + $s * 4, $p + $s * 8, 20, 20, $s * 8, $s * 12, 8, 12);
138 | imagecopyresized($av, $im, $p, $p + $s * 8, 44, 20, $s * 4, $s * 12, 4, 12);
139 | imagecopyresized($av, $im, $p + $s * 12, $p + $s * 8, 36, 52, $s * 4, $s * 12, 4, 12);
140 | imagecopyresized($av, $im, $p + $s * 4, $p + $s * 8 + $s * 12, 4, 20, $s * 4, $s * 12, 4, 12);
141 | imagecopyresized($av, $im, $p + $s * 8, $p + $s * 8 + $s * 12, 20, 52, $s * 4, $s * 12, 4, 12);
142 |
143 | // Right
144 | imagecopyresized($av, $im, $p + $s * $g + $s * 16, $p, 0, 8, $s * 8, $s * 8, 8, 8);
145 | imagecopyresized($av, $im, $p + $s * $g + $s * 18, $p + $s * 8, 40, 20, $s * 4, $s * 12, 4, 12);
146 | imagecopyresized($av, $im, $p + $s * $g + $s * 18, $p + $s * 8 + $s * 12, 0, 20, $s * 4, $s * 12, 4, 12);
147 |
148 | // Back
149 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p, 24, 8, $s * 8, $s * 8, 8, 8);
150 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p + $s * 8, 32, 20, $s * 8, $s * 12, 8, 12);
151 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 24, $p + $s * 8, 44, 52, $s * 4, $s * 12, 4, 12);
152 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 36, $p + $s * 8, 52, 20, $s * 4, $s * 12, 4, 12);
153 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p + $s * 8 + $s * 12, 28, 52, $s * 4, $s * 12, 4, 12);
154 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 32, $p + $s * 8 + $s * 12, 12, 20, $s * 4, $s * 12, 4, 12);
155 |
156 | // Left
157 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 40, $p, 16, 8, $s * 8, $s * 8, 8, 8);
158 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 42, $p + $s * 8, 40, 52, $s * 4, $s * 12, 4, 12);
159 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 42, $p + $s * 8 +$s * 12, 24, 52, $s * 4, $s * 12, 4, 12);
160 |
161 | // Black Hat Issue
162 | imagecolortransparent($im, imagecolorat($im, 63, 0));
163 |
164 | // Face Accessories
165 | imagecopyresized($av, $im, $p + $s * 4, $p, 40, 8, $s * 8, $s * 8, 8, 8);
166 | imagecopyresized($av, $im, $p + $s * $g + $s * 16, $p, 32, 8, $s * 8, $s * 8, 8, 8);
167 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p, 56, 8, $s * 8, $s * 8, 8, 8);
168 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 40, $p, 48, 8, $s * 8, $s * 8, 8, 8);
169 |
170 | // Body Accessories
171 | imagecopyresized($av, $im, $p + $s * 4, $p + $s * 8, 20, 36, $s * 8, $s * 12, 8, 12);
172 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p + $s * 8, 32, 36, $s * 8, $s * 12, 8, 12);
173 |
174 | // Arm Accessores
175 | imagecopyresized($av, $im, $p, $p + $s * 8, 44, 36, $s * 4, $s * 12, 4, 12);
176 | imagecopyresized($av, $im, $p + $s * 12, $p + $s * 8, 52, 52, $s * 4, $s * 12, 4, 12);
177 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 24, $p + $s * 8, 60, 52, $s * 4, $s * 12, 4, 12);
178 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 36, $p + $s * 8, 52, 36, $s * 4, $s * 12, 4, 12);
179 | imagecopyresized($av, $im, $p + $s * $g + $s * 18, $p + $s * 8, 40, 36, $s * 4, $s * 12, 4, 12);
180 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 42, $p + $s * 8, 56, 52, $s * 4, $s * 12, 4, 12);
181 |
182 | // Leg Accessores
183 | imagecopyresized($av, $im, $p + $s * 4, $p + $s * 8 + $s * 12, 4, 36, $s * 4, $s * 12, 4, 12);
184 | imagecopyresized($av, $im, $p + $s * 8, $p + $s * 8 + $s * 12, 4, 52, $s * 4, $s * 12, 4, 12);
185 | imagecopyresized($av, $im, $p + $s * $g + $s * 18, $p + $s * 8 + $s * 12, 0, 36, $s * 4, $s * 12, 4, 12);
186 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p + $s * 8 + $s * 12, 12, 52, $s * 4, $s * 12, 4, 12);
187 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 32, $p + $s * 8 + $s * 12, 12, 36, $s * 4, $s * 12, 4, 12);
188 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 42, $p + $s * 8 +$s * 12, 8, 52, $s * 4, $s * 12, 4, 12);
189 | }
190 | } else {
191 | $mi = imagecreatetruecolor(64, 32);
192 | imagecopyresampled($mi, $im, 0, 0, 64 - 1, 0, 64, 32, -64, 32);
193 | imagesavealpha($mi, true);
194 | imagefill($mi, 0, 0, imagecolorallocatealpha($mi, 0, 0, 0, 127));
195 |
196 | // Front
197 | imagecopyresized($av, $im, $p + $s * 4, $p, 8, 8, $s * 8, $s * 8, 8, 8);
198 | imagecopyresized($av, $im, $p + $s * 4, $p + $s * 8, 20, 20, $s * 8, $s * 12, 8, 12);
199 | imagecopyresized($av, $im, $p, $p + $s * 8, 44, 20, $s * 4, $s * 12, 4, 12);
200 | imagecopyresized($av, $mi, $p + $s * 12, $p + $s * 8, 16, 20, $s * 4, $s * 12, 4, 12);
201 | imagecopyresized($av, $im, $p + $s * 4, $p + $s * 8 + $s * 12, 4, 20, $s * 4, $s * 12, 4, 12);
202 | imagecopyresized($av, $mi, $p + $s * 8, $p + $s * 8 + $s * 12, 56, 20, $s * 4, $s * 12, 4, 12);
203 |
204 | // Right
205 | imagecopyresized($av, $im, $p + $s * $g + $s * 16, $p, 0, 8, $s * 8, $s * 8, 8, 8);
206 | imagecopyresized($av, $im, $p + $s * $g + $s * 18, $p + $s * 8, 40, 20, $s * 4, $s * 12, 4, 12);
207 | imagecopyresized($av, $im, $p + $s * $g + $s * 18, $p + $s * 8 + $s * 12, 0, 20, $s * 4, $s * 12, 4, 12);
208 |
209 | // Back
210 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p, 24, 8, $s * 8, $s * 8, 8, 8);
211 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p + $s * 8, 32, 20, $s * 8, $s * 12, 8, 12);
212 | imagecopyresized($av, $mi, $p + $s * $g * 2 + $s * 24, $p + $s * 8, 8, 20, $s * 4, $s * 12, 4, 12);
213 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 36, $p + $s * 8, 52, 20, $s * 4, $s * 12, 4, 12);
214 | imagecopyresized($av, $mi, $p + $s * $g * 2 + $s * 28, $p + $s * 8 + $s * 12, 48, 20, $s * 4, $s * 12, 4, 12);
215 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 32, $p + $s * 8 + $s * 12, 12, 20, $s * 4, $s * 12, 4, 12);
216 |
217 | // Left
218 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 40, $p, 16, 8, $s * 8, $s * 8, 8, 8);
219 | imagecopyresized($av, $mi, $p + $s * $g * 3 + $s * 42, $p + $s * 8, 20, 20, $s * 4, $s * 12, 4, 12);
220 | imagecopyresized($av, $mi, $p + $s * $g * 3 + $s * 42, $p + $s * 8 +$s * 12, 60, 20, $s * 4, $s * 12, 4, 12);
221 |
222 | // Black Hat Issue
223 | imagecolortransparent($im, imagecolorat($im, 63, 0));
224 |
225 | // Accessories
226 | imagecopyresized($av, $im, $p + $s * 4, $p, 40, 8, $s * 8, $s * 8, 8, 8);
227 | imagecopyresized($av, $im, $p + $s * $g + $s * 16, $p, 32, 8, $s * 8, $s * 8, 8, 8);
228 | imagecopyresized($av, $im, $p + $s * $g * 2 + $s * 28, $p, 56, 8, $s * 8, $s * 8, 8, 8);
229 | imagecopyresized($av, $im, $p + $s * $g * 3 + $s * 40, $p, 48, 8, $s * 8, $s * 8, 8, 8);
230 |
231 | imagedestroy($mi);
232 | }
233 |
234 | header('Content-type: image/png');
235 | imagepng($av);
236 | imagedestroy($im);
237 | imagedestroy($av);
238 |
--------------------------------------------------------------------------------