mineskin 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mineskin-0.1.0/LICENSE +21 -0
- mineskin-0.1.0/PKG-INFO +81 -0
- mineskin-0.1.0/README.md +52 -0
- mineskin-0.1.0/pyproject.toml +39 -0
- mineskin-0.1.0/setup.cfg +4 -0
- mineskin-0.1.0/src/mineskin/__init__.py +254 -0
- mineskin-0.1.0/src/mineskin/__init__.pyi +55 -0
- mineskin-0.1.0/src/mineskin/utils.py +20 -0
- mineskin-0.1.0/src/mineskin/utils.pyi +12 -0
- mineskin-0.1.0/src/mineskin.egg-info/PKG-INFO +81 -0
- mineskin-0.1.0/src/mineskin.egg-info/SOURCES.txt +12 -0
- mineskin-0.1.0/src/mineskin.egg-info/dependency_links.txt +1 -0
- mineskin-0.1.0/src/mineskin.egg-info/requires.txt +2 -0
- mineskin-0.1.0/src/mineskin.egg-info/top_level.txt +1 -0
mineskin-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kiber2009
|
|
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.
|
mineskin-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mineskin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Simple Python library for working with Minecraft skins
|
|
5
|
+
Author-email: Kiber2009 <92222946+kiber2009@users.noreply.github.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Kiber2009/mineskin
|
|
8
|
+
Project-URL: Repository, https://github.com/Kiber2009/mineskin.git
|
|
9
|
+
Project-URL: Issues, https://github.com/Kiber2009/mineskin/issues
|
|
10
|
+
Keywords: minecraft skin
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.16
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Classifier: Topic :: Games/Entertainment
|
|
19
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
20
|
+
Classifier: Topic :: Multimedia :: Graphics :: Editors
|
|
21
|
+
Classifier: Topic :: Multimedia :: Graphics :: Editors :: Raster-Based
|
|
22
|
+
Classifier: Natural Language :: English
|
|
23
|
+
Requires-Python: >=3.14
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: numpy>=2.4.6
|
|
27
|
+
Requires-Dist: pillow>=12.2.0
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# mineskin
|
|
31
|
+
|
|
32
|
+
Simple Python library for working with Minecraft skins
|
|
33
|
+
|
|
34
|
+
# Installation
|
|
35
|
+
|
|
36
|
+
Install `mineskin` from PyPI using your favorite package manager
|
|
37
|
+
|
|
38
|
+
- `pip install mineskin`
|
|
39
|
+
- `uv add mineskin`
|
|
40
|
+
- `poetry add mineskin`
|
|
41
|
+
|
|
42
|
+
# Usage
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
# Import library
|
|
46
|
+
import mineskin
|
|
47
|
+
|
|
48
|
+
# Read skin from file
|
|
49
|
+
with mineskin.MinecraftSkin.open("path/to/skin.png") as skin:
|
|
50
|
+
skin.load()
|
|
51
|
+
|
|
52
|
+
# Check skin information
|
|
53
|
+
print(skin.format)
|
|
54
|
+
print(skin.is_slim())
|
|
55
|
+
print(skin.has_overlay)
|
|
56
|
+
|
|
57
|
+
# Optimize skin
|
|
58
|
+
skin.optimize()
|
|
59
|
+
|
|
60
|
+
# Convert skin to old (before 1.8) format
|
|
61
|
+
old_skin = skin.convert(mineskin.MinecraftSkinFormat.OLD)
|
|
62
|
+
|
|
63
|
+
# Save the result
|
|
64
|
+
old_skin.save("path/to/result.png")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
# Building from source
|
|
68
|
+
|
|
69
|
+
> [!WARNING]
|
|
70
|
+
> Make sure uv installed on your system
|
|
71
|
+
|
|
72
|
+
- Clone the repo:
|
|
73
|
+
```shell
|
|
74
|
+
git clone https://github.com/Kiber2009/mineskin.git
|
|
75
|
+
cd mineskin
|
|
76
|
+
```
|
|
77
|
+
- Build using uv
|
|
78
|
+
```shell
|
|
79
|
+
uv build
|
|
80
|
+
```
|
|
81
|
+
- Distribution will be available in `dist` directory
|
mineskin-0.1.0/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# mineskin
|
|
2
|
+
|
|
3
|
+
Simple Python library for working with Minecraft skins
|
|
4
|
+
|
|
5
|
+
# Installation
|
|
6
|
+
|
|
7
|
+
Install `mineskin` from PyPI using your favorite package manager
|
|
8
|
+
|
|
9
|
+
- `pip install mineskin`
|
|
10
|
+
- `uv add mineskin`
|
|
11
|
+
- `poetry add mineskin`
|
|
12
|
+
|
|
13
|
+
# Usage
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
# Import library
|
|
17
|
+
import mineskin
|
|
18
|
+
|
|
19
|
+
# Read skin from file
|
|
20
|
+
with mineskin.MinecraftSkin.open("path/to/skin.png") as skin:
|
|
21
|
+
skin.load()
|
|
22
|
+
|
|
23
|
+
# Check skin information
|
|
24
|
+
print(skin.format)
|
|
25
|
+
print(skin.is_slim())
|
|
26
|
+
print(skin.has_overlay)
|
|
27
|
+
|
|
28
|
+
# Optimize skin
|
|
29
|
+
skin.optimize()
|
|
30
|
+
|
|
31
|
+
# Convert skin to old (before 1.8) format
|
|
32
|
+
old_skin = skin.convert(mineskin.MinecraftSkinFormat.OLD)
|
|
33
|
+
|
|
34
|
+
# Save the result
|
|
35
|
+
old_skin.save("path/to/result.png")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
# Building from source
|
|
39
|
+
|
|
40
|
+
> [!WARNING]
|
|
41
|
+
> Make sure uv installed on your system
|
|
42
|
+
|
|
43
|
+
- Clone the repo:
|
|
44
|
+
```shell
|
|
45
|
+
git clone https://github.com/Kiber2009/mineskin.git
|
|
46
|
+
cd mineskin
|
|
47
|
+
```
|
|
48
|
+
- Build using uv
|
|
49
|
+
```shell
|
|
50
|
+
uv build
|
|
51
|
+
```
|
|
52
|
+
- Distribution will be available in `dist` directory
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mineskin"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
requires-python = ">=3.14"
|
|
5
|
+
dependencies = [
|
|
6
|
+
"numpy>=2.4.6",
|
|
7
|
+
"pillow>=12.2.0",
|
|
8
|
+
]
|
|
9
|
+
authors = [{ name = "Kiber2009", email = "92222946+kiber2009@users.noreply.github.com" }]
|
|
10
|
+
description = "Simple Python library for working with Minecraft skins"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
license = "MIT"
|
|
13
|
+
keywords = ["minecraft skin"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Programming Language :: Python :: 3.14",
|
|
19
|
+
"Programming Language :: Python :: 3.15",
|
|
20
|
+
"Programming Language :: Python :: 3.16",
|
|
21
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
22
|
+
"Topic :: Games/Entertainment",
|
|
23
|
+
"Topic :: Multimedia :: Graphics",
|
|
24
|
+
"Topic :: Multimedia :: Graphics :: Editors",
|
|
25
|
+
"Topic :: Multimedia :: Graphics :: Editors :: Raster-Based",
|
|
26
|
+
"Natural Language :: English"
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/Kiber2009/mineskin"
|
|
31
|
+
#Documentation = "https://readthedocs.org"
|
|
32
|
+
Repository = "https://github.com/Kiber2009/mineskin.git"
|
|
33
|
+
Issues = "https://github.com/Kiber2009/mineskin/issues"
|
|
34
|
+
#Changelog = "https://github.com/Kiber2009/mineskin/blob/master/CHANGELOG.md"
|
|
35
|
+
|
|
36
|
+
[dependency-groups]
|
|
37
|
+
dev = [
|
|
38
|
+
"ruff>=0.15.14",
|
|
39
|
+
]
|
mineskin-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
from enum import Enum, auto
|
|
2
|
+
from .utils import check_all_regions_transparency
|
|
3
|
+
|
|
4
|
+
from PIL import Image, ImageDraw
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MinecraftSkinFormat(Enum):
|
|
8
|
+
OLD = auto()
|
|
9
|
+
NEW_1_8 = auto()
|
|
10
|
+
|
|
11
|
+
@staticmethod
|
|
12
|
+
def detect(img):
|
|
13
|
+
match img.size:
|
|
14
|
+
case (64, 64):
|
|
15
|
+
return MinecraftSkinFormat.NEW_1_8
|
|
16
|
+
case (64, 32):
|
|
17
|
+
return MinecraftSkinFormat.OLD
|
|
18
|
+
case _:
|
|
19
|
+
raise ValueError("Unable to determine skin format")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class MinecraftSkin:
|
|
23
|
+
def __init__(self, img):
|
|
24
|
+
self._img = img
|
|
25
|
+
self._fmt = MinecraftSkinFormat.detect(img)
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def open(fp):
|
|
29
|
+
return MinecraftSkin(Image.open(fp))
|
|
30
|
+
|
|
31
|
+
def close(self):
|
|
32
|
+
self._img.close()
|
|
33
|
+
|
|
34
|
+
def __enter__(self):
|
|
35
|
+
return self
|
|
36
|
+
|
|
37
|
+
def __exit__(self, _exc_type, _exc_val, _exc_tb):
|
|
38
|
+
self.close()
|
|
39
|
+
|
|
40
|
+
def load(self):
|
|
41
|
+
self._img.load()
|
|
42
|
+
|
|
43
|
+
def save(self, fp):
|
|
44
|
+
self._img.save(fp)
|
|
45
|
+
|
|
46
|
+
def is_slim(self, check_overlay=True):
|
|
47
|
+
match self._fmt:
|
|
48
|
+
case MinecraftSkinFormat.OLD:
|
|
49
|
+
return False
|
|
50
|
+
case MinecraftSkinFormat.NEW_1_8:
|
|
51
|
+
return check_all_regions_transparency(
|
|
52
|
+
self._img,
|
|
53
|
+
(
|
|
54
|
+
# Right arm
|
|
55
|
+
(50, 16, 52, 20),
|
|
56
|
+
(54, 20, 56, 32),
|
|
57
|
+
# Right arm overlay
|
|
58
|
+
*(
|
|
59
|
+
((50, 32, 52, 36), (54, 36, 56, 48))
|
|
60
|
+
if check_overlay
|
|
61
|
+
else ()
|
|
62
|
+
),
|
|
63
|
+
# Left arm
|
|
64
|
+
(42, 48, 44, 52),
|
|
65
|
+
(46, 52, 48, 64),
|
|
66
|
+
# Left arm overlay
|
|
67
|
+
*(
|
|
68
|
+
((58, 48, 60, 52), (62, 52, 64, 64))
|
|
69
|
+
if check_overlay
|
|
70
|
+
else ()
|
|
71
|
+
),
|
|
72
|
+
),
|
|
73
|
+
)
|
|
74
|
+
case _:
|
|
75
|
+
raise NotImplementedError
|
|
76
|
+
|
|
77
|
+
def optimize(self, keep_ears=False):
|
|
78
|
+
match self._fmt:
|
|
79
|
+
case MinecraftSkinFormat.OLD:
|
|
80
|
+
draw = ImageDraw.Draw(self._img)
|
|
81
|
+
draw.rectangle(
|
|
82
|
+
(0, 0, 8, 8), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
83
|
+
)
|
|
84
|
+
draw.rectangle(
|
|
85
|
+
(56, 0, 64, 8), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
86
|
+
)
|
|
87
|
+
draw.rectangle(
|
|
88
|
+
(0, 16, 4, 20), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
89
|
+
)
|
|
90
|
+
draw.rectangle(
|
|
91
|
+
(12, 16, 20, 20), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
92
|
+
)
|
|
93
|
+
draw.rectangle(
|
|
94
|
+
(36, 16, 44, 20), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
95
|
+
)
|
|
96
|
+
draw.rectangle(
|
|
97
|
+
(52, 16, 56, 20), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
98
|
+
)
|
|
99
|
+
draw.rectangle(
|
|
100
|
+
(56, 16, 64, 32), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
101
|
+
)
|
|
102
|
+
if keep_ears:
|
|
103
|
+
draw.rectangle(
|
|
104
|
+
(24, 0, 25, 1), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
105
|
+
)
|
|
106
|
+
draw.rectangle(
|
|
107
|
+
(37, 0, 38, 1), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
108
|
+
)
|
|
109
|
+
draw.rectangle(
|
|
110
|
+
(24, 7, 38, 8), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
111
|
+
)
|
|
112
|
+
draw.rectangle(
|
|
113
|
+
(38, 0, 40, 8), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
114
|
+
)
|
|
115
|
+
else:
|
|
116
|
+
draw.rectangle(
|
|
117
|
+
(24, 0, 40, 8), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
118
|
+
)
|
|
119
|
+
case MinecraftSkinFormat.NEW_1_8:
|
|
120
|
+
draw = ImageDraw.Draw(self._img)
|
|
121
|
+
draw.rectangle(
|
|
122
|
+
(0, 0, 8, 8), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
123
|
+
)
|
|
124
|
+
draw.rectangle(
|
|
125
|
+
(56, 0, 64, 8), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
126
|
+
)
|
|
127
|
+
draw.rectangle(
|
|
128
|
+
(0, 16, 4, 20), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
129
|
+
)
|
|
130
|
+
draw.rectangle(
|
|
131
|
+
(12, 16, 20, 20), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
132
|
+
)
|
|
133
|
+
draw.rectangle(
|
|
134
|
+
(36, 16, 44, 20), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
135
|
+
)
|
|
136
|
+
draw.rectangle(
|
|
137
|
+
(52, 16, 56, 20), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
138
|
+
)
|
|
139
|
+
draw.rectangle(
|
|
140
|
+
(0, 32, 4, 36), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
141
|
+
)
|
|
142
|
+
draw.rectangle(
|
|
143
|
+
(12, 32, 20, 36), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
144
|
+
)
|
|
145
|
+
draw.rectangle(
|
|
146
|
+
(36, 32, 44, 36), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
147
|
+
)
|
|
148
|
+
draw.rectangle(
|
|
149
|
+
(52, 32, 56, 36), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
150
|
+
)
|
|
151
|
+
draw.rectangle(
|
|
152
|
+
(0, 48, 4, 52), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
153
|
+
)
|
|
154
|
+
draw.rectangle(
|
|
155
|
+
(12, 48, 20, 52), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
156
|
+
)
|
|
157
|
+
draw.rectangle(
|
|
158
|
+
(28, 48, 36, 52), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
159
|
+
)
|
|
160
|
+
draw.rectangle(
|
|
161
|
+
(44, 48, 52, 52), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
162
|
+
)
|
|
163
|
+
draw.rectangle(
|
|
164
|
+
(60, 48, 64, 52), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
165
|
+
)
|
|
166
|
+
draw.rectangle(
|
|
167
|
+
(56, 16, 64, 48), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
168
|
+
)
|
|
169
|
+
if keep_ears:
|
|
170
|
+
draw.rectangle(
|
|
171
|
+
(24, 0, 25, 1), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
172
|
+
)
|
|
173
|
+
draw.rectangle(
|
|
174
|
+
(37, 0, 38, 1), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
175
|
+
)
|
|
176
|
+
draw.rectangle(
|
|
177
|
+
(24, 7, 38, 8), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
178
|
+
)
|
|
179
|
+
draw.rectangle(
|
|
180
|
+
(38, 0, 40, 8), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
181
|
+
)
|
|
182
|
+
else:
|
|
183
|
+
draw.rectangle(
|
|
184
|
+
(24, 0, 40, 8), fill=(0, 0, 0, 0), outline=(0, 0, 0, 0), width=0
|
|
185
|
+
)
|
|
186
|
+
case _:
|
|
187
|
+
raise NotImplementedError
|
|
188
|
+
|
|
189
|
+
def convert(self, fmt, ignore_slim=False, use_left_arm=False, use_left_leg=False):
|
|
190
|
+
if self._fmt == fmt:
|
|
191
|
+
return self._img.copy()
|
|
192
|
+
match (self._fmt, fmt):
|
|
193
|
+
case (MinecraftSkinFormat.OLD, MinecraftSkinFormat.NEW_1_8):
|
|
194
|
+
img = Image.new("RGBA", (64, 64), (0, 0, 0, 0))
|
|
195
|
+
img.paste(self._img, box=(0, 0))
|
|
196
|
+
img.paste(self._img.crop((0, 16, 16, 32)), box=(16, 48))
|
|
197
|
+
img.paste(self._img.crop((40, 16, 56, 32)), box=(32, 48))
|
|
198
|
+
return img
|
|
199
|
+
case (MinecraftSkinFormat.NEW_1_8, MinecraftSkinFormat.OLD):
|
|
200
|
+
if (not ignore_slim) and self.is_slim(check_overlay=False):
|
|
201
|
+
raise ValueError("Slim skins cannot be converted to old format")
|
|
202
|
+
if not (use_left_leg or use_left_arm):
|
|
203
|
+
return self._img.crop((0, 0, 64, 32))
|
|
204
|
+
img = Image.new("RGBA", (64, 32), (0, 0, 0, 0))
|
|
205
|
+
img.paste(self._img.crop((0, 0, 64, 16)), box=(0, 0))
|
|
206
|
+
img.paste(self._img.crop((16, 16, 40, 32)), box=(16, 16))
|
|
207
|
+
if use_left_arm:
|
|
208
|
+
img.paste(self._img.crop((16, 48, 32, 64)), box=(0, 16))
|
|
209
|
+
else:
|
|
210
|
+
img.paste(self._img.crop((0, 16, 16, 32)), box=(0, 16))
|
|
211
|
+
if use_left_leg:
|
|
212
|
+
img.paste(self._img.crop((32, 48, 48, 64)), box=(40, 16))
|
|
213
|
+
else:
|
|
214
|
+
img.paste(self._img.crop((40, 16, 56, 32)), box=(40, 16))
|
|
215
|
+
return img
|
|
216
|
+
case _:
|
|
217
|
+
raise NotImplementedError
|
|
218
|
+
|
|
219
|
+
@property
|
|
220
|
+
def format(self):
|
|
221
|
+
return self._fmt
|
|
222
|
+
|
|
223
|
+
@property
|
|
224
|
+
def has_overlay(self):
|
|
225
|
+
match self._fmt:
|
|
226
|
+
case MinecraftSkinFormat.OLD:
|
|
227
|
+
return not check_all_regions_transparency(
|
|
228
|
+
self._img,
|
|
229
|
+
(
|
|
230
|
+
(40, 0, 56, 8),
|
|
231
|
+
(32, 8, 64, 16),
|
|
232
|
+
),
|
|
233
|
+
)
|
|
234
|
+
case MinecraftSkinFormat.NEW_1_8:
|
|
235
|
+
return not check_all_regions_transparency(
|
|
236
|
+
self._img,
|
|
237
|
+
(
|
|
238
|
+
(40, 0, 56, 8),
|
|
239
|
+
(32, 8, 64, 16),
|
|
240
|
+
(4, 32, 12, 36),
|
|
241
|
+
(20, 32, 36, 36),
|
|
242
|
+
(44, 32, 52, 36),
|
|
243
|
+
(0, 36, 56, 48),
|
|
244
|
+
(4, 48, 12, 52),
|
|
245
|
+
(0, 52, 16, 64),
|
|
246
|
+
(52, 48, 60, 52),
|
|
247
|
+
(48, 52, 64, 64),
|
|
248
|
+
),
|
|
249
|
+
)
|
|
250
|
+
case _:
|
|
251
|
+
raise NotImplementedError
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
__all__ = ("MinecraftSkin", "MinecraftSkinFormat")
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from types import TracebackType
|
|
2
|
+
import os
|
|
3
|
+
from enum import Enum, auto
|
|
4
|
+
from typing import IO
|
|
5
|
+
|
|
6
|
+
from PIL.Image import Image
|
|
7
|
+
|
|
8
|
+
class MinecraftSkinFormat(Enum):
|
|
9
|
+
OLD = auto()
|
|
10
|
+
NEW_1_8 = auto()
|
|
11
|
+
|
|
12
|
+
@staticmethod
|
|
13
|
+
def detect(img: Image) -> MinecraftSkinFormat:
|
|
14
|
+
"""
|
|
15
|
+
Determines the format of a skin
|
|
16
|
+
|
|
17
|
+
:param img: Skin image
|
|
18
|
+
|
|
19
|
+
:raise ValueError: Unable to determine format
|
|
20
|
+
"""
|
|
21
|
+
...
|
|
22
|
+
|
|
23
|
+
class MinecraftSkin:
|
|
24
|
+
def __init__(self, img: Image) -> None: ...
|
|
25
|
+
@staticmethod
|
|
26
|
+
def open(
|
|
27
|
+
fp: str | bytes | os.PathLike[str] | os.PathLike[bytes] | IO[bytes],
|
|
28
|
+
) -> MinecraftSkin: ...
|
|
29
|
+
def close(self) -> None: ...
|
|
30
|
+
def __enter__(self) -> MinecraftSkin: ...
|
|
31
|
+
def __exit__[T: BaseException](
|
|
32
|
+
self,
|
|
33
|
+
_exc_type: type[T] | None,
|
|
34
|
+
_exc_val: T | None,
|
|
35
|
+
_exc_tb: TracebackType | None,
|
|
36
|
+
) -> None: ...
|
|
37
|
+
def load(self) -> None: ...
|
|
38
|
+
def save(
|
|
39
|
+
self, fp: str | bytes | os.PathLike[str] | os.PathLike[bytes] | IO[bytes]
|
|
40
|
+
) -> None: ...
|
|
41
|
+
def is_slim(self, check_overlay: bool = True) -> bool: ...
|
|
42
|
+
def optimize(self, keep_ears: bool = False) -> None: ...
|
|
43
|
+
def convert(
|
|
44
|
+
self,
|
|
45
|
+
fmt: MinecraftSkinFormat,
|
|
46
|
+
ignore_slim: bool = False,
|
|
47
|
+
use_left_arm: bool = False,
|
|
48
|
+
use_left_leg: bool = False,
|
|
49
|
+
) -> Image: ...
|
|
50
|
+
@property
|
|
51
|
+
def format(self) -> MinecraftSkinFormat: ...
|
|
52
|
+
@property
|
|
53
|
+
def has_overlay(self) -> bool: ...
|
|
54
|
+
|
|
55
|
+
__all__ = ("MinecraftSkin", "MinecraftSkinFormat")
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def is_region_fully_transparent_np(image, box):
|
|
5
|
+
if image.mode not in ("RGBA", "LA", "PA"):
|
|
6
|
+
return False
|
|
7
|
+
|
|
8
|
+
region = image.crop(box)
|
|
9
|
+
arr = np.array(region)
|
|
10
|
+
|
|
11
|
+
if region.mode == "RGBA":
|
|
12
|
+
alpha_channel = arr[:, :, 3]
|
|
13
|
+
else:
|
|
14
|
+
alpha_channel = arr[:, :, 1]
|
|
15
|
+
|
|
16
|
+
return np.all(alpha_channel == 0)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def check_all_regions_transparency(image, boxes):
|
|
20
|
+
return all(is_region_fully_transparent_np(image, box) for box in boxes)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
|
|
3
|
+
from PIL.Image import Image
|
|
4
|
+
|
|
5
|
+
def is_region_fully_transparent_np(
|
|
6
|
+
image: Image,
|
|
7
|
+
box: tuple[float, float, float, float],
|
|
8
|
+
) -> bool: ...
|
|
9
|
+
def check_all_regions_transparency(
|
|
10
|
+
image: Image,
|
|
11
|
+
boxes: Iterable[tuple[float, float, float, float]],
|
|
12
|
+
) -> bool: ...
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mineskin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Simple Python library for working with Minecraft skins
|
|
5
|
+
Author-email: Kiber2009 <92222946+kiber2009@users.noreply.github.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Kiber2009/mineskin
|
|
8
|
+
Project-URL: Repository, https://github.com/Kiber2009/mineskin.git
|
|
9
|
+
Project-URL: Issues, https://github.com/Kiber2009/mineskin/issues
|
|
10
|
+
Keywords: minecraft skin
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.16
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Classifier: Topic :: Games/Entertainment
|
|
19
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
20
|
+
Classifier: Topic :: Multimedia :: Graphics :: Editors
|
|
21
|
+
Classifier: Topic :: Multimedia :: Graphics :: Editors :: Raster-Based
|
|
22
|
+
Classifier: Natural Language :: English
|
|
23
|
+
Requires-Python: >=3.14
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: numpy>=2.4.6
|
|
27
|
+
Requires-Dist: pillow>=12.2.0
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# mineskin
|
|
31
|
+
|
|
32
|
+
Simple Python library for working with Minecraft skins
|
|
33
|
+
|
|
34
|
+
# Installation
|
|
35
|
+
|
|
36
|
+
Install `mineskin` from PyPI using your favorite package manager
|
|
37
|
+
|
|
38
|
+
- `pip install mineskin`
|
|
39
|
+
- `uv add mineskin`
|
|
40
|
+
- `poetry add mineskin`
|
|
41
|
+
|
|
42
|
+
# Usage
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
# Import library
|
|
46
|
+
import mineskin
|
|
47
|
+
|
|
48
|
+
# Read skin from file
|
|
49
|
+
with mineskin.MinecraftSkin.open("path/to/skin.png") as skin:
|
|
50
|
+
skin.load()
|
|
51
|
+
|
|
52
|
+
# Check skin information
|
|
53
|
+
print(skin.format)
|
|
54
|
+
print(skin.is_slim())
|
|
55
|
+
print(skin.has_overlay)
|
|
56
|
+
|
|
57
|
+
# Optimize skin
|
|
58
|
+
skin.optimize()
|
|
59
|
+
|
|
60
|
+
# Convert skin to old (before 1.8) format
|
|
61
|
+
old_skin = skin.convert(mineskin.MinecraftSkinFormat.OLD)
|
|
62
|
+
|
|
63
|
+
# Save the result
|
|
64
|
+
old_skin.save("path/to/result.png")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
# Building from source
|
|
68
|
+
|
|
69
|
+
> [!WARNING]
|
|
70
|
+
> Make sure uv installed on your system
|
|
71
|
+
|
|
72
|
+
- Clone the repo:
|
|
73
|
+
```shell
|
|
74
|
+
git clone https://github.com/Kiber2009/mineskin.git
|
|
75
|
+
cd mineskin
|
|
76
|
+
```
|
|
77
|
+
- Build using uv
|
|
78
|
+
```shell
|
|
79
|
+
uv build
|
|
80
|
+
```
|
|
81
|
+
- Distribution will be available in `dist` directory
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/mineskin/__init__.py
|
|
5
|
+
src/mineskin/__init__.pyi
|
|
6
|
+
src/mineskin/utils.py
|
|
7
|
+
src/mineskin/utils.pyi
|
|
8
|
+
src/mineskin.egg-info/PKG-INFO
|
|
9
|
+
src/mineskin.egg-info/SOURCES.txt
|
|
10
|
+
src/mineskin.egg-info/dependency_links.txt
|
|
11
|
+
src/mineskin.egg-info/requires.txt
|
|
12
|
+
src/mineskin.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mineskin
|