|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Image; |
|
6
|
|
|
|
|
7
|
|
|
use App\Helpers\Storage\Files\SkinsStorage; |
|
8
|
|
|
use App\Image\Sections\Avatar; |
|
9
|
|
|
use App\Image\Sections\Skin; |
|
10
|
|
|
use App\Minecraft\MinecraftDefaults; |
|
11
|
|
|
|
|
12
|
|
|
class Rendering |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param string|null $uuid |
|
16
|
|
|
* @param int $size |
|
17
|
|
|
* @param string $type |
|
18
|
|
|
* |
|
19
|
|
|
* @throws Exceptions\ImageCreateFromPngFailedException |
|
20
|
|
|
* @throws Exceptions\ImageTrueColorCreationFailedException |
|
21
|
|
|
* @throws Exceptions\InvalidSectionSpecifiedException |
|
22
|
|
|
* |
|
23
|
|
|
* @return Avatar |
|
24
|
|
|
*/ |
|
25
|
|
|
public function avatar(?string $uuid, int $size, $type = ImageSection::FRONT): Avatar |
|
26
|
|
|
{ |
|
27
|
|
|
$avatar = new Avatar( |
|
28
|
|
|
$this->imagePath($uuid) |
|
29
|
|
|
); |
|
30
|
|
|
$avatar->render($size, $type); |
|
31
|
|
|
|
|
32
|
|
|
return $avatar; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param string|null $uuid |
|
37
|
|
|
* @param int $size |
|
38
|
|
|
* @param int|null $lastUpdateTimestamp |
|
39
|
|
|
* |
|
40
|
|
|
* @throws Exceptions\SkinNotFountException |
|
41
|
|
|
* @throws \Throwable |
|
42
|
|
|
* |
|
43
|
|
|
* @return IsometricAvatar |
|
44
|
|
|
*/ |
|
45
|
|
|
public function isometricAvatar(?string $uuid, int $size, int $lastUpdateTimestamp = null): IsometricAvatar |
|
46
|
|
|
{ |
|
47
|
|
|
if ($lastUpdateTimestamp === null) { |
|
48
|
|
|
$lastUpdateTimestamp = \time(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$isometricAvatar = new IsometricAvatar( |
|
52
|
|
|
$uuid ?? MinecraftDefaults::STEVE_DEFAULT_SKIN_NAME, |
|
53
|
|
|
$lastUpdateTimestamp |
|
54
|
|
|
); |
|
55
|
|
|
$isometricAvatar->render($size); |
|
56
|
|
|
|
|
57
|
|
|
return $isometricAvatar; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param string|null $uuid |
|
62
|
|
|
* @param int $size |
|
63
|
|
|
* @param string $type |
|
64
|
|
|
* |
|
65
|
|
|
* @throws \Throwable |
|
66
|
|
|
* |
|
67
|
|
|
* @return Skin |
|
68
|
|
|
*/ |
|
69
|
|
|
public function skin(?string $uuid, int $size, $type = ImageSection::FRONT): Skin |
|
70
|
|
|
{ |
|
71
|
|
|
$skin = new Skin( |
|
72
|
|
|
$this->imagePath($uuid) |
|
73
|
|
|
); |
|
74
|
|
|
$skin->render($size, $type); |
|
75
|
|
|
|
|
76
|
|
|
return $skin; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param string|null $uuid |
|
81
|
|
|
* |
|
82
|
|
|
* @throws \Exception |
|
83
|
|
|
* |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
|
|
private function imagePath(?string $uuid): string |
|
87
|
|
|
{ |
|
88
|
|
|
return $uuid !== null ? SkinsStorage::getPath($uuid) : SkinsStorage::getPath(MinecraftDefaults::STEVE_DEFAULT_SKIN_NAME); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|