-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjamo2.py
195 lines (162 loc) · 9.31 KB
/
jamo2.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# 자음 + 모음 + 자음
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 k in [1, 3, 4, 6, 7, 8, 10, 12, 13, 15, 16, 17, 18, 19]:
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')
consonant2 = Image.open('./crops/' + str(k) + '.PNG') # 받침
consonant = rescale_image_ratio(consonant, rescale_height=50)
vowel = rescale_image_ratio(vowel, rescale_height=60)
consonant2 = rescale_image_ratio(consonant2, rescale_height=40)
background.paste(consonant, (10, 10))
background.paste(vowel, (int(10+consonant.width*1.1), 5))
center = 10 + int((consonant.width*1.1+vowel.width) * 0.5)
background.paste(consonant2, (center-int(consonant2.width*0.5), 65))
background.save(
path + '/letter_' + str(i).zfill(2) + "_" + str(j).zfill(2) + "_" + str(k).zfill(2) + ".PNG")
# ㅓ ㅔ ㅕ ㅖ
def combine_letters_2():
for k in [1, 3, 4, 6, 7, 8, 10, 12, 13, 15, 16, 17, 18, 19]:
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')
consonant2 = Image.open('./crops/' + str(k) + '.PNG')
consonant = rescale_image_ratio(consonant, rescale_height=50)
vowel = rescale_image_ratio(vowel, rescale_height=60)
consonant2 = rescale_image_ratio(consonant2, rescale_height=40)
background.paste(consonant, (10, 10))
background.paste(vowel, (int(10+consonant.width), 5))
center = 10 + int((consonant.width+vowel.width) * 0.5)
background.paste(consonant2, (center-int(consonant2.width*0.5), 5+int(vowel.height)))
background.save(
path + '/letter_' + str(i).zfill(2) + "_" + str(j).zfill(2) + "_" + str(k).zfill(2) + ".PNG")
# ㅗ ㅛ
def combine_letters_3():
for k in [1, 3, 4, 6, 7, 8, 10, 12, 13, 15, 16, 17, 18, 19]:
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')
consonant2 = Image.open('./crops/' + str(k) + '.PNG')
consonant = rescale_image_ratio(consonant, rescale_height=50)
vowel = rescale_image_ratio(vowel, rescale_width=78)
consonant2 = rescale_image_ratio(consonant2, rescale_height=40)
background.paste(consonant, (50, 10))
center = 50 + int(consonant.width*0.5)
background.paste(vowel, (center-39, 60))
background.paste(consonant2, (center-int(consonant2.width*0.5), 60+int(vowel.height*1.1)))
background.save(
path + '/letter_' + str(i).zfill(2) + "_" + str(j).zfill(2) + "_" + str(k).zfill(2) + ".PNG")
# ㅜ ㅠ ㅡ
def combine_letters_4():
for k in [1, 3, 4, 6, 7, 8, 10, 12, 13, 15, 16, 17, 18, 19]:
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')
consonant2 = Image.open('./crops/' + str(k) + '.PNG')
consonant = rescale_image_ratio(consonant, rescale_height=50)
vowel = rescale_image_ratio(vowel, rescale_width=78)
consonant2 = rescale_image_ratio(consonant2, rescale_height=40)
background.paste(consonant, (50, 10))
center = 50 + int(consonant.width*0.5)
background.paste(vowel, (center-39, 63))
background.paste(consonant2, (center-int(consonant2.width*0.5), 60+int(vowel.height*1.1)))
background.save(
path + '/letter_' + str(i).zfill(2) + "_" + str(j).zfill(2) + "_" + str(k).zfill(2) + ".PNG")
# ㅘ ㅙ ㅚ ㅞ ㅝ ㅟ ㅢ
def combine_letters_5():
# ㅗ + ㅏ ㅐ ㅣ
for k in [1, 3, 4, 6, 7, 8, 10, 12, 13, 15, 16, 17, 18, 19]:
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')
consonant2 = Image.open('./crops/' + str(k) + '.PNG')
consonant = rescale_image_ratio(consonant, rescale_width=50)
vowel = rescale_image_ratio(vowel, rescale_width=60)
vowel2 = rescale_image_ratio(vowel2, rescale_height=int((consonant.height+vowel.height)*1.1))
consonant2 = rescale_image_ratio(consonant2, rescale_width=40)
background.paste(consonant, (20, 30))
background.paste(vowel, (15, 30+consonant.height))
background.paste(vowel2, (int(15+vowel.width), 30))
center = 15 + int((vowel.width+vowel2.width)*0.5)
background.paste(consonant2, (center-int(consonant2.width*0.5), 30+vowel2.height))
background.save(
path + '/letter_' + str(i).zfill(2) + "_" + str(index).zfill(2) + "_" + str(k).zfill(2) + ".PNG")
index += 1
# ㅜ + ㅓ ㅔ ㅣ
for k in [1, 3, 4, 6, 7, 8, 10, 12, 13, 15, 16, 17, 18, 19]:
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')
consonant2 = Image.open('./crops/' + str(k) + '.PNG')
consonant = rescale_image_ratio(consonant, rescale_width=50)
vowel = rescale_image_ratio(vowel, rescale_width=60)
vowel2 = rescale_image_ratio(vowel2, rescale_height=int((consonant.height+vowel.height)))
consonant2 = rescale_image_ratio(consonant2, rescale_width=40)
background.paste(consonant, (20, 30))
background.paste(vowel, (15, 30+consonant.height))
background.paste(vowel2, (int(15+vowel.width), 30))
center = 15 + int((vowel.width+vowel2.width)*0.5)
background.paste(consonant2, (center-int(consonant2.width*0.5), 30+vowel2.height))
background.save(
path + '/letter_' + str(i).zfill(2) + "_" + str(index).zfill(2) + "_" + str(k).zfill(2) + ".PNG")
index += 1
# ㅡ + ㅣ
for k in [1, 3, 4, 6, 7, 8, 10, 12, 13, 15, 16, 17, 18, 19]:
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')
consonant2 = Image.open('./crops/' + str(k) + '.PNG')
consonant = rescale_image_ratio(consonant, rescale_width=50)
vowel = rescale_image_ratio(vowel, rescale_width=60)
vowel2 = rescale_image_ratio(vowel2, rescale_height=int((consonant.height+vowel.height)))
consonant2 = rescale_image_ratio(consonant2, rescale_width=40)
background.paste(consonant, (20, 30))
background.paste(vowel, (15, 30+consonant.height))
background.paste(vowel2, (int(15+vowel.width), 30))
center = 15 + int((vowel.width+vowel2.width)*0.5)
background.paste(consonant2, (center-int(consonant2.width*0.5), 30+vowel2.height))
background.save(path + '/letter_' + str(i).zfill(2) + "_39_" + str(k).zfill(2) + ".PNG")
def run():
print('jamo2 시작')
combine_letters_1()
combine_letters_2()
combine_letters_3()
combine_letters_4()
combine_letters_5()
print('jamo2 끝')