-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_cropper.py
71 lines (61 loc) · 2.38 KB
/
image_cropper.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Importing Image class from PIL module
from PIL import Image
# Opens a image in RGB mode
im = Image.open("images\\UNO_cards_deck.png")
# Size of the image in pixels (size of original image)
# (This is not mandatory)
width, height = im.size
for col in range(5):
for row in range(14):
# Setting the points for cropped image
card_width = width / 14
card_height = height / 8
left = row * card_width
top = col * card_height
right = (row + 1) * card_width
bottom = (col + 1) * card_height
# Cropped image of above dimension
# (It will not change original image)
im1 = im.crop((left, top, right, bottom))
# Shows the image in image viewer
if col == 0:
if row < 10:
im1.save(f"images\\red_{row }.png")
elif row == 10:
im1.save(f"images\\red_skip.png")
elif row == 11:
im1.save(f"images\\red_reverse.png")
elif row == 12:
im1.save(f"images\\red_plustwo.png")
elif row == 13:
im1.save(f"images\\wild_wild.png")
elif col == 1:
if row < 10:
im1.save(f"images\\yellow_{row }.png")
elif row == 10:
im1.save(f"images\\yellow_skip.png")
elif row == 11:
im1.save(f"images\\yellow_reverse.png")
elif row == 12:
im1.save(f"images\\yellow_plustwo.png")
elif col == 2:
if row < 10:
im1.save(f"images\\green_{row }.png")
elif row == 10:
im1.save(f"images\\green_skip.png")
elif row == 11:
im1.save(f"images\\green_reverse.png")
elif row == 12:
im1.save(f"images\\green_plustwo.png")
elif col == 3:
if row < 10:
im1.save(f"images\\blue_{row }.png")
elif row == 10:
im1.save(f"images\\blue_skip.png")
elif row == 11:
im1.save(f"images\\blue_reverse.png")
elif row == 12:
im1.save(f"images\\blue_plustwo.png")
if col == 4:
if row == 13:
im1.save(f"images\\wild_draw4.png")