-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcut_image.py
57 lines (35 loc) · 1.01 KB
/
cut_image.py
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
"""
Usage:
python cut_image.py
Cuts the toolbar.png image into 18 small PNG's.
"""
from typing import Tuple
from PIL import Image
im = Image.open("toolbar.png")
def number_to_xy(n) -> Tuple[int, int]:
x = n % 2
y = (n - (n % 2)) / 2
return (x, y)
def get_crop(img: Image.Image, index: int):
x, y = number_to_xy(index) # Of the form (i,j) (ints)
sw = 82
sh = 86
# top_left_x = 3 + x * (sw + 7)
# top_left_y = 3 + y * (sh + 7.5)
top_left_x = 3 + x * (sw + 7)
top_left_y = 5 + y * (sh + 11.5)
box = (top_left_x, top_left_y, top_left_x + sw, top_left_y + sh)
im2 = img.copy()
return im2.crop(box)
# ys 2 94 192 289 388
# diffs 90, 98, 97, 98, 99
def crop_a_little_bit(img: Image.Image):
h = img.height
w = img.width
return img.copy().crop((0, 6, w, h))
if __name__ == "__main__":
new_im = get_crop(im, 0)
for i in range(18):
l = get_crop(im, i)
# l.show()
l.save(f"public/icons/{i}.png", format="png", optimize=False)