-
Notifications
You must be signed in to change notification settings - Fork 1
/
jamo1.py
154 lines (121 loc) · 6.16 KB
/
jamo1.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# 1 자음 + 모음
from PIL import Image
path = './combinations'
def rescale_image_ratio(image, rescale_width=None, rescale_height=None):
width, height = image.size
if rescale_width is not None:
# Calculate new height preserving aspect ratio
aspect_ratio = width / height
new_width = int(rescale_width)
new_height = int(new_width / aspect_ratio)
elif rescale_height is not None:
# Calculate new width preserving aspect ratio
aspect_ratio = height / width
new_height = int(rescale_height)
new_width = int(new_height / aspect_ratio)
else:
raise ValueError("Either 'rescale_width' or 'rescale_height' must be provided.")
return image.resize((new_width, new_height), Image.LANCZOS)
# ㅏ ㅐ ㅑ ㅒ ㅣ
def combine_letters_1():
for j in [20, 21, 22, 23, 40]:
for i in range(1, 20):
background = Image.open('./images/background.png')
consonant = Image.open('./crops/' + str(i) + '.PNG')
vowel = Image.open('./crops/' + str(j) + '.PNG')
consonant = rescale_image_ratio(consonant, rescale_width=70)
vowel = rescale_image_ratio(vowel, rescale_height=90)
background.paste(consonant, (30, 30))
background.paste(vowel, (int(30 + consonant.width*1.1), int(30+consonant.height*0.5-45)))
background.save(path + '/letter_' + str(i).zfill(2) + "_" + str(j).zfill(2) + ".PNG")
# ㅓ ㅔ ㅕ ㅖ
def combine_letters_2():
for j in [24, 25, 26, 27]:
for i in range(1, 20):
background = Image.open('./images/background.png')
consonant = Image.open('./crops/' + str(i) + '.PNG')
vowel = Image.open('./crops/' + str(j) + '.PNG')
consonant = rescale_image_ratio(consonant, rescale_width=70)
vowel = rescale_image_ratio(vowel, rescale_height=90)
background.paste(vowel, (int(30 + consonant.width), int(30+consonant.height*0.5-45)))
background.paste(consonant, (30, 30))
background.save(path + '/letter_' + str(i).zfill(2) + "_" + str(j).zfill(2) + ".PNG")
# ㅗ ㅛ
def combine_letters_3():
for j in [28, 32]:
for i in range(1, 20):
background = Image.open('./images/background.png')
consonant = Image.open('./crops/' + str(i) + '.PNG')
vowel = Image.open('./crops/' + str(j) + '.PNG')
consonant = rescale_image_ratio(consonant, rescale_width=70)
vowel = rescale_image_ratio(vowel, rescale_width=90)
background.paste(consonant, (30, 30))
background.paste(vowel, (20, 30+consonant.height))
background.save(path + '/letter_' + str(i).zfill(2) + "_" + str(j).zfill(2) + ".PNG")
# ㅜ ㅠ ㅡ
def combine_letters_4():
for j in [33, 37, 38]:
for i in range(1, 20):
background = Image.open('./images/background.png')
consonant = Image.open('./crops/' + str(i) + '.PNG')
vowel = Image.open('./crops/' + str(j) + '.PNG')
consonant = rescale_image_ratio(consonant, rescale_width=70)
vowel = rescale_image_ratio(vowel, rescale_width=90)
background.paste(consonant, (30, 30))
background.paste(vowel, (20, int(30 + consonant.height*1.1)))
background.save(path + '/letter_' + str(i).zfill(2) + "_" + str(j).zfill(2) + ".PNG")
# ㅘ ㅙ ㅚ ㅞ ㅝ ㅟ ㅢ
def combine_letters_5():
# ㅗ + ㅏ ㅐ ㅣ
index = 29
for j in [20, 21, 40]:
for i in range(1, 20):
background = Image.open('./images/background.png')
consonant = Image.open('./crops/' + str(i) + '.PNG')
vowel = Image.open('./crops/28.PNG')
vowel2 = Image.open('./crops/' + str(j) + '.PNG')
consonant = rescale_image_ratio(consonant, rescale_width=70)
vowel = rescale_image_ratio(vowel, rescale_width=80)
vowel2 = rescale_image_ratio(vowel2, rescale_height=consonant.height+vowel.height)
background.paste(consonant, (20, 30))
background.paste(vowel, (15, 30+consonant.height))
background.paste(vowel2, (int(15+vowel.width*1.1), 30))
background.save(path + '/letter_' + str(i).zfill(2) + "_" + str(index).zfill(2) + ".PNG")
index += 1
# ㅜ + ㅓ ㅔ ㅣ
index = 34
for j in [24, 25, 40]:
for i in range(1, 20):
background = Image.open('./images/background.png')
consonant = Image.open('./crops/' + str(i) + '.PNG')
vowel = Image.open('./crops/33.PNG')
vowel2 = Image.open('./crops/' + str(j) + '.PNG')
consonant = rescale_image_ratio(consonant, rescale_width=70)
vowel = rescale_image_ratio(vowel, rescale_width=80)
vowel2 = rescale_image_ratio(vowel2, rescale_height=consonant.height+vowel.height)
background.paste(consonant, (20, 30))
background.paste(vowel, (15, 30+consonant.height))
background.paste(vowel2, (15+vowel.width, 30))
background.save(path + '/letter_' + str(i).zfill(2) + "_" + str(index).zfill(2) + ".PNG")
index += 1
# ㅡ + ㅣ
for i in range(1, 20):
background = Image.open('./images/background.png')
consonant = Image.open('./crops/' + str(i) + '.PNG')
vowel = Image.open('./crops/38.PNG')
vowel2 = Image.open('./crops/40.PNG')
consonant = rescale_image_ratio(consonant, rescale_width=70)
vowel = rescale_image_ratio(vowel, rescale_width=80)
vowel2 = rescale_image_ratio(vowel2, rescale_height=int(consonant.height*1.1+vowel.height))
background.paste(consonant, (20, 30))
background.paste(vowel, (15, int(30 + consonant.height*1.1)))
background.paste(vowel2, (15+vowel.width, 30))
background.save(path + '/letter_' + str(i).zfill(2) + "_39.PNG")
def run():
print('jamo1 시작')
combine_letters_1()
combine_letters_2()
combine_letters_3()
combine_letters_4()
combine_letters_5()
print('jamo1 끝')