chohj06ms commited on
Commit
61296fa
·
verified ·
1 Parent(s): 32bd464

Delete generate.py

Browse files
Files changed (1) hide show
  1. generate.py +0 -359
generate.py DELETED
@@ -1,359 +0,0 @@
1
- import os
2
-
3
- import numpy as np
4
-
5
- import gradio as gr
6
- import fn
7
- import edimg
8
- import edgif
9
- from PIL import Image, ImageDraw, ImageFont, ImageColor, ImageFilter, ImageSequence
10
-
11
- if os.path.exists("./data"):
12
- print("./data is None")
13
- if os.path.exists("/data"):
14
- print("/data is Exist!") # 폴더가 이미 존재할 경우 출력
15
-
16
-
17
- img_blank = Image.open('resource/blank.png')
18
-
19
-
20
- def sorting(img_type, img_static, img_dynamic_file, obj_color, obj_color_picker, ai_num, txt_color, txt_color_picker, member_name_dropdown, group_name_radio, group_name_txt, obj_num, obj_alphabet, obj_alphabet_txt, obj_serial, rounded):
21
- match img_type:
22
- case "Image":
23
- if img_static == None:
24
- gr.Warning("Upload the image first")
25
- return "resource/upload_first.png", "resource/upload_first.png", None
26
- img = front_static(img_static, obj_color, obj_color_picker, ai_num, txt_color, txt_color_picker, member_name_dropdown, group_name_radio, group_name_txt, obj_num, obj_alphabet, obj_alphabet_txt, obj_serial, rounded)
27
- return img, img, None
28
- case "Gif":
29
- if img_dynamic_file == None:
30
- gr.Warning("Upload the gif first")
31
- return "resource/upload_first.png", "resource/upload_first.png", None
32
- overlay = front_static(img_blank, obj_color, obj_color_picker, ai_num, txt_color, txt_color_picker, member_name_dropdown, group_name_radio, group_name_txt, obj_num, obj_alphabet, obj_alphabet_txt, obj_serial, rounded)
33
- gif = Image.open(img_dynamic_file)
34
- edgif.attach_gif(gif, overlay, rounded)
35
- return "output.gif", "output.gif", "output.gif"
36
-
37
- def front_static(img, obj_color, obj_color_picker, ai_num, txt_color, txt_color_picker, member_name_dropdown, group_name_radio, group_name_txt, obj_num, obj_alphabet, obj_alphabet_txt, obj_serial, rounded):
38
-
39
- match obj_color:
40
- case "Atom01":
41
- obj_color = "#ffdd00"
42
- front_side = edimg.color("resource/front_side.png", obj_color)
43
- img.paste(front_side, (0, 0), front_side)
44
- case "Binary01":
45
- obj_color = "#00ff01"
46
- front_side = edimg.color("resource/front_side.png", obj_color)
47
- img.paste(front_side, (0, 0), front_side)
48
- case "Cream01":
49
- obj_color = "#ff7477"
50
- front_side = edimg.color("resource/front_side.png", obj_color)
51
- img.paste(front_side, (0, 0), front_side)
52
- case "Divine01":
53
- obj_color = "#a226f5"
54
- front_side = edimg.color("resource/front_side.png", obj_color)
55
- img.paste(front_side, (0, 0), front_side)
56
- case "Special":
57
- img = edimg.paste_img(img, "resource/special_side.png", (0, 0))
58
- case "Other color":
59
- obj_color = obj_color_picker
60
- front_side = edimg.color("resource/front_side.png", obj_color)
61
- img.paste(front_side, (0, 0), front_side)
62
- case "AI Color":
63
- front_side = edimg.color_ai(ai_num)
64
- img.paste(front_side, (1038, 0), front_side)
65
-
66
-
67
- match txt_color:
68
- case "White":
69
- txt_color_r = 255
70
- txt_color_g = 255
71
- txt_color_b = 255
72
- txt_color_hex = "#FFFFFF"
73
- case "Black":
74
- txt_color_r = 0
75
- txt_color_g = 0
76
- txt_color_b = 0
77
- txt_color_hex = "#000000"
78
- case _:
79
- txt_color_r, txt_color_g, txt_color_b = fn.hex_to_rgb(txt_color_picker)
80
- txt_color_hex = txt_color_picker
81
-
82
-
83
- if member_name_dropdown:
84
- img_name = edimg.txt(member_name_dropdown, txt_color_r, txt_color_g, txt_color_b, 61, 270, "l")
85
- img.paste(img_name, (1050, 161), img_name)
86
-
87
- match group_name_radio:
88
- case "tripleS":
89
- img_group_name = edimg.txt(group_name_radio, txt_color_r, txt_color_g, txt_color_b, 61, 270, "r")
90
- img.paste(img_group_name, (1050, 1240), img_group_name)
91
- case "ARTMS":
92
- img_artms_side = edimg.color("resource/artms_side.png", txt_color_hex)
93
- img.paste(img_artms_side, (1081, 1371), img_artms_side)
94
-
95
- case "Other":
96
- img_group_name = edimg.txt(group_name_txt, txt_color_r, txt_color_g, txt_color_b, 61, 270, "r")
97
- img.paste(img_group_name, (1050, 1240), img_group_name)
98
-
99
- if obj_num != "" and obj_alphabet != "":
100
- if obj_alphabet == "Other":
101
- obj_alphabet = obj_alphabet_txt
102
- img_obj_num = edimg.txt(obj_num+obj_alphabet, txt_color_r, txt_color_g, txt_color_b, 75, 270, "r")
103
- img.paste(img_obj_num, (1050, 452), img_obj_num)
104
-
105
- if obj_serial:
106
- img_serial = edimg.serial(obj_serial, txt_color_r, txt_color_g, txt_color_b, 75)
107
- img.paste(img_serial, (1046, 871), img_serial)
108
- if rounded:
109
- img = edimg.rounded(img)
110
-
111
- krtime = fn.get_kr_time()
112
- img_jpeg = img.convert('RGB')
113
- img_jpeg.save(f'/data/cache/{member_name_dropdown}_{group_name_radio}_{obj_num}{obj_alphabet}_{krtime}.jpg', quality=90)
114
- return img
115
-
116
- back_ui = Image.open("resource/back_ui.png")
117
- outline_ui = Image.open("resource/outline.png")
118
-
119
-
120
- sign_positions = {
121
- 1: (31, 1068),
122
- 2: (0, 1103),
123
- 3: (34, 1101),
124
- 4: (1, 1053),
125
- 5: (79, 1100),
126
- 6: (0, 1057),
127
- 7: (0, 1116),
128
- 8: (20, 1109),
129
- 9: (26, 1109),
130
- 10: (42, 1104),
131
- 11: (31, 1105),
132
- 12: (0, 1065),
133
- 13: (58, 1108),
134
- 14: (0, 1110),
135
- 15: (0, 1105),
136
- 16: (49, 1056),
137
- 17: (61, 1105),
138
- 18: (84, 1118),
139
- 19: (39, 1167),
140
- 20: (170, 1105),
141
- 21: (64, 1124),
142
- 22: (41, 1146),
143
- 23: (52, 1113),
144
- 24: (65, 1129),
145
-
146
- 25: (38, 1148),
147
- 26: (61, 1100),
148
- 27: (52, 1113),
149
- 28: (46, 1022),
150
- 29: (62, 1131)
151
- }
152
-
153
- cream01 = Image.open("resource/cream01.png")
154
- atom01 = Image.open("resource/atom01.png")
155
- binary01 = Image.open("resource/binary01.png")
156
- divine01 = Image.open("resource/divine01.png")
157
-
158
- right_modhaus = Image.open("resource/right_modhaus.png")
159
- img_qr_white_space = Image.new("RGB", (335, 335), 'white')
160
- def back(obj_color, obj_color_picker, ai_num, txt_color, txt_color_picker, group_name_radio, group_name_txt, member_name_dropdown, obj_num, obj_alphabet, obj_alphabet_txt, obj_serial, obj_outline_color, obj_outline_color_picker, logo_radio, class_radio, class_txt, season_radio, season_txt, season_txt_outline, sign, qr_url_dropdown, qr_Logo_radio, right_btn, rounded_back):
161
- match obj_outline_color:
162
- case "White":
163
- outline = edimg.color(outline_ui, "#FFFFFF")
164
- case "Black":
165
- outline = edimg.color(outline_ui, "#000000")
166
- case _:
167
- outline = edimg.color(outline_ui, obj_outline_color_picker)
168
-
169
-
170
-
171
- match obj_color:
172
- case "Atom01":
173
- obj_color = "#ffdd00"
174
- img = Image.new("RGB", (1164, 1800), obj_color)
175
- case "Binary01":
176
- obj_color = "#00ff01"
177
- img = Image.new("RGB", (1164, 1800), obj_color)
178
- case "Cream01":
179
- obj_color = "#ff7477"
180
- img = Image.new("RGB", (1164, 1800), obj_color)
181
- case "Divine01":
182
- obj_color = "#a226f5"
183
- img = Image.new("RGB", (1164, 1800), obj_color)
184
- case "Special":
185
- img = Image.open('resource/special_back.png')
186
- case "Other color":
187
- obj_color = obj_color_picker
188
- img = Image.new("RGB", (1164, 1800), obj_color)
189
- case "AI Color":
190
- img = edimg.color_ai_back(ai_num)
191
- case _:
192
- img = Image.new("RGB", (1164, 1800), "#FFFFFF")
193
-
194
- img.paste(outline, (0,0), outline)
195
-
196
- match txt_color:
197
- case "White":
198
- txt_color_r = 255
199
- txt_color_g = 255
200
- txt_color_b = 255
201
- txt_color_hex = "#FFFFFF"
202
- case "Black":
203
- txt_color_r = 0
204
- txt_color_g = 0
205
- txt_color_b = 0
206
- txt_color_hex = "#000000"
207
- case _:
208
- txt_color_r, txt_color_g, txt_color_b = fn.hex_to_rgb(txt_color_picker)
209
- txt_color_hex = txt_color_picker
210
-
211
- back_ui_colored = edimg.color(back_ui, txt_color_hex)
212
- img.paste(back_ui_colored, (0, 0), back_ui_colored)
213
-
214
-
215
- match logo_radio:
216
- case "tripleS":
217
- logo = edimg.color('resource/triples_logo.png', txt_color_hex)
218
- img.paste(logo, (61, 162), logo)
219
- case "ARTMS":
220
- logo = edimg.color('resource/artms_logo.png', txt_color_hex)
221
- img.paste(logo, (61, 162), logo)
222
-
223
-
224
- if member_name_dropdown:
225
- img_name = edimg.txt(member_name_dropdown, txt_color_r, txt_color_g, txt_color_b, 130, 0, "l", "font/Helvetica_Neue_LT_Std_65_Medium.otf", (800, 136))
226
- img.paste(img_name, (54, 466), img_name)
227
-
228
- img_name_side = edimg.txt(member_name_dropdown, txt_color_r, txt_color_g, txt_color_b, 61, 270, "l")
229
- img.paste(img_name_side, (932, 159),img_name_side)
230
-
231
- if obj_num:
232
- if obj_alphabet == "Other":
233
- obj_alphabet = obj_alphabet_txt
234
- img_obj_num_side = edimg.txt(obj_num+obj_alphabet, txt_color_r,txt_color_g,txt_color_b, 75, 270, "r")
235
- img.paste(img_obj_num_side, (951, 448), img_obj_num_side)
236
-
237
-
238
- if obj_serial:
239
- img_obj_serial_side = edimg.serial(obj_serial, txt_color_r,txt_color_g,txt_color_b, 75)
240
- img.paste(img_obj_serial_side, (943, 867), img_obj_serial_side)
241
-
242
- match group_name_radio:
243
- case "tripleS":
244
- img_group_name_side = edimg.txt("tripleS", txt_color_r, txt_color_g, txt_color_b, 61, 270, "r")
245
- img.paste(img_group_name_side, (943, 1238), img_group_name_side)
246
- case "ARTMS":
247
- img_group_name_side = edimg.color("resource/artms_side.png", txt_color_hex)
248
- img.paste(img_group_name_side, (974, 1371), img_group_name_side)
249
- case "Other":
250
- img_group_name_side = edimg.txt(group_name_txt, txt_color_r, txt_color_g, txt_color_b, 61, 270, "r")
251
- img.paste(img_group_name_side, (943, 1238), img_group_name_side)
252
- group_name_radio = group_name_txt
253
-
254
- match class_radio:
255
- case "Zero" | "First" | "Double" | "Special":
256
- img_class = edimg.txt(class_radio, txt_color_r, txt_color_g, txt_color_b, 130, 0, "l", "font/Helvetica_Neue_LT_Std_65_Medium.otf", (800, 136))
257
- img.paste(img_class, (54, 700), img_class)
258
- case "Other":
259
- img_class = edimg.txt(class_txt, txt_color_r, txt_color_g, txt_color_b, 130, 0, "l", "font/Helvetica_Neue_LT_Std_65_Medium.otf", (800, 136))
260
- img.paste(img_class, (54, 700), img_class)
261
-
262
-
263
-
264
- match season_radio:
265
- case "Atom01":
266
- img_atom01 = edimg.color(atom01, txt_color_hex)
267
- img.paste(img_atom01, (63, 951), img_atom01)
268
- case "Binary01":
269
- img_binary01 = edimg.color(binary01, txt_color_hex)
270
- img.paste(img_binary01, (63, 951), img_binary01)
271
- case "Cream01":
272
- img_cream01 = edimg.color(cream01, txt_color_hex)
273
- img.paste(img_cream01, (62, 950), img_cream01)
274
- case "Divine01":
275
- img_divine01 = edimg.color(divine01, txt_color_hex)
276
- img.paste(img_divine01, (61, 951), img_divine01)
277
- case "Other":
278
- img_season = edimg.txt(season_txt, txt_color_r, txt_color_g, txt_color_b, 130, 0, "l", "font/Helvetica_Neue_LT_Std_65_Medium.otf", (1100, 136))
279
- x = edimg.calculate_size(season_txt, 130, "font/Helvetica_Neue_LT_Std_65_Medium.otf")
280
- img_season_outline = edimg.txt(season_txt_outline, txt_color_r, txt_color_g, txt_color_b, 135, 0, "l", "font/Helvetica_Neue_LT_Std_75_Bold_Outline.otf", (1100, 136))
281
- img.paste(img_season,(53, 936), img_season)
282
- img.paste(img_season_outline, (53 + x, 936), img_season_outline)
283
-
284
- if sign != None:
285
- sign = sign + 1
286
- colored_icon = edimg.color(f'sign/{sign}.png', txt_color_hex)
287
- if sign in sign_positions:
288
- position = sign_positions[sign]
289
- img.paste(colored_icon, position, colored_icon)
290
-
291
-
292
- if qr_url_dropdown:
293
- url_txt = fn.url_mapping(qr_url_dropdown)
294
- img_qr = edimg.qr(url_txt)
295
-
296
- match qr_Logo_radio:
297
- case "tripleS":
298
- img_qr_icon = edimg.qr_icon("resource/qr_icon_triples.png")
299
- img_qr.paste(img_qr_icon, (126, 126), img_qr_icon)
300
-
301
- img_qr = edimg.resize_img(img_qr, 335,335)
302
- img.paste(img_qr, (555, 1098))
303
- else:
304
- img.paste(img_qr_white_space,(555, 1098))
305
-
306
- if right_btn:
307
- img_right_modhaus = edimg.color(right_modhaus, txt_color_hex)
308
- img.paste(img_right_modhaus, (61,1604), img_right_modhaus)
309
-
310
- if rounded_back:
311
- img = edimg.rounded(img)
312
-
313
- krtime = fn.get_kr_time()
314
- img_jpeg = img.convert('RGB')
315
- img_jpeg.save(f'/data/cache/{member_name_dropdown}_{group_name_radio}_{class_radio}_{obj_num}{obj_alphabet}_{krtime}.jpg', quality=90)
316
- return img, img
317
-
318
-
319
- make_image_first = Image.open("resource/make_image_first.png")
320
-
321
- def ex_gen(img_front, file_front_path, img_back, count, blur, blur_strength, watermark):
322
- if img_back == None:
323
- gr.Warning("Make two images, front and back")
324
- return make_image_first, make_image_first
325
- if img_front == None and file_front_path == None:
326
- gr.Warning("Make two images, front and back")
327
- return make_image_first, make_image_first
328
- if file_front_path:
329
- file_front = Image.open(file_front_path)
330
- match count:
331
- case "One File":
332
- img_back = img_back.resize(file_front.size)
333
- filename, _ = os.path.splitext(os.path.basename(file_front_path))
334
- edimg.makegif(file_front, img_back)
335
- return f"exgif.gif", img_back
336
- case "Two Files":
337
- return file_front, img_back
338
- if blur:
339
- img_front = img_front.filter(ImageFilter.GaussianBlur(blur_strength))
340
- img_back = img_back.filter(ImageFilter.GaussianBlur(blur_strength))
341
-
342
- if watermark:
343
- img_txt = edimg.txt(watermark, 255, 255, 255, 210, 50, "l", "font/Helvetica_Neue_LT_Std_75_Bold.otf",(1338, 222), 120)
344
- img_front.paste(img_txt, (65, 333), img_txt)
345
- img_back.paste(img_txt, (65, 333), img_txt)
346
-
347
- match count:
348
- case "One File":
349
- img = Image.new("RGBA", (2328, 1800), (0, 0, 0, 0))
350
- img_front = edimg.rounded(img_front)
351
- img_back = edimg.rounded(img_back)
352
- img.paste(img_front, (0, 0), img_front)
353
- img.paste(img_back, (1164, 0), img_back)
354
- return img, img_blank
355
- case "Two Files":
356
- img_front = edimg.rounded(img_front)
357
- img_back = edimg.rounded(img_back)
358
- return img_front, img_back
359
-