Spaces:
Running
Running
File size: 14,771 Bytes
624937a |
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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
import os
import numpy as np
import gradio as gr
import fn
import edimg
import edgif
from PIL import Image, ImageDraw, ImageFont, ImageColor, ImageFilter, ImageSequence
img_blank = Image.open('resource/blank.png')
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):
match img_type:
case "Image":
if img_static == None:
gr.Warning("Upload the image first")
return "resource/upload_first.png", "resource/upload_first.png", None
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)
return img, img, None
case "Gif":
if img_dynamic_file == None:
gr.Warning("Upload the gif first")
return "resource/upload_first.png", "resource/upload_first.png", None
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)
gif = Image.open(img_dynamic_file)
edgif.attach_gif(gif, overlay, rounded)
return "output.gif", "output.gif", "output.gif"
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):
match obj_color:
case "Atom01":
obj_color = "#ffdd00"
front_side = edimg.color("resource/front_side.png", obj_color)
img.paste(front_side, (0, 0), front_side)
case "Binary01":
obj_color = "#00ff01"
front_side = edimg.color("resource/front_side.png", obj_color)
img.paste(front_side, (0, 0), front_side)
case "Cream01":
obj_color = "#ff7477"
front_side = edimg.color("resource/front_side.png", obj_color)
img.paste(front_side, (0, 0), front_side)
case "Divine01":
obj_color = "#a226f5"
front_side = edimg.color("resource/front_side.png", obj_color)
img.paste(front_side, (0, 0), front_side)
case "Special":
img = edimg.paste_img(img, "resource/special_side.png", (0, 0))
case "Other color":
obj_color = obj_color_picker
front_side = edimg.color("resource/front_side.png", obj_color)
img.paste(front_side, (0, 0), front_side)
case "AI Color":
front_side = edimg.color_ai(ai_num)
img.paste(front_side, (1038, 0), front_side)
match txt_color:
case "White":
txt_color_r = 255
txt_color_g = 255
txt_color_b = 255
txt_color_hex = "#FFFFFF"
case "Black":
txt_color_r = 0
txt_color_g = 0
txt_color_b = 0
txt_color_hex = "#000000"
case _:
txt_color_r, txt_color_g, txt_color_b = fn.hex_to_rgb(txt_color_picker)
txt_color_hex = txt_color_picker
if member_name_dropdown:
img_name = edimg.txt(member_name_dropdown, txt_color_r, txt_color_g, txt_color_b, 61, 270, "l")
img.paste(img_name, (1050, 161), img_name)
match group_name_radio:
case "tripleS":
img_group_name = edimg.txt(group_name_radio, txt_color_r, txt_color_g, txt_color_b, 61, 270, "r")
img.paste(img_group_name, (1050, 1240), img_group_name)
case "ARTMS":
img_artms_side = edimg.color("resource/artms_side.png", txt_color_hex)
img.paste(img_artms_side, (1081, 1371), img_artms_side)
case "Other":
img_group_name = edimg.txt(group_name_txt, txt_color_r, txt_color_g, txt_color_b, 61, 270, "r")
img.paste(img_group_name, (1050, 1240), img_group_name)
if obj_num != "" and obj_alphabet != "":
if obj_alphabet == "Other":
obj_alphabet = obj_alphabet_txt
img_obj_num = edimg.txt(obj_num+obj_alphabet, txt_color_r, txt_color_g, txt_color_b, 75, 270, "r")
img.paste(img_obj_num, (1050, 452), img_obj_num)
if obj_serial:
img_serial = edimg.serial(obj_serial, txt_color_r, txt_color_g, txt_color_b, 75)
img.paste(img_serial, (1046, 871), img_serial)
if rounded:
img = edimg.rounded(img)
krtime = fn.get_kr_time()
img_jpeg = img.convert('RGB')
img_jpeg.save(f'./data/cache/{member_name_dropdown}_{group_name_radio}_{obj_num}{obj_alphabet}_{krtime}.jpg', quality=90)
return img
back_ui = Image.open("resource/back_ui.png")
outline_ui = Image.open("resource/outline.png")
sign_positions = {
1: (31, 1068),
2: (0, 1103),
3: (34, 1101),
4: (1, 1053),
5: (79, 1100),
6: (0, 1057),
7: (0, 1116),
8: (20, 1109),
9: (26, 1109),
10: (42, 1104),
11: (31, 1105),
12: (0, 1065),
13: (58, 1108),
14: (0, 1110),
15: (0, 1105),
16: (49, 1056),
17: (61, 1105),
18: (84, 1118),
19: (39, 1167),
20: (170, 1105),
21: (64, 1124),
22: (41, 1146),
23: (52, 1113),
24: (65, 1129),
25: (38, 1148),
26: (61, 1100),
27: (52, 1113),
28: (46, 1022),
29: (62, 1131)
}
cream01 = Image.open("resource/cream01.png")
atom01 = Image.open("resource/atom01.png")
binary01 = Image.open("resource/binary01.png")
divine01 = Image.open("resource/divine01.png")
right_modhaus = Image.open("resource/right_modhaus.png")
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):
match obj_outline_color:
case "White":
outline = edimg.color(outline_ui, "#FFFFFF")
case "Black":
outline = edimg.color(outline_ui, "#000000")
case _:
outline = edimg.color(outline_ui, obj_outline_color_picker)
match obj_color:
case "Atom01":
obj_color = "#ffdd00"
img = Image.new("RGB", (1164, 1800), obj_color)
case "Binary01":
obj_color = "#00ff01"
img = Image.new("RGB", (1164, 1800), obj_color)
case "Cream01":
obj_color = "#ff7477"
img = Image.new("RGB", (1164, 1800), obj_color)
case "Divine01":
obj_color = "#a226f5"
img = Image.new("RGB", (1164, 1800), obj_color)
case "Special":
img = Image.open('resource/special_back.png')
case "Other color":
obj_color = obj_color_picker
img = Image.new("RGB", (1164, 1800), obj_color)
case "AI Color":
img = edimg.color_ai_back(ai_num)
case _:
img = Image.new("RGB", (1164, 1800), "#FFFFFF")
img.paste(outline, (0,0), outline)
match txt_color:
case "White":
txt_color_r = 255
txt_color_g = 255
txt_color_b = 255
txt_color_hex = "#FFFFFF"
case "Black":
txt_color_r = 0
txt_color_g = 0
txt_color_b = 0
txt_color_hex = "#000000"
case _:
txt_color_r, txt_color_g, txt_color_b = fn.hex_to_rgb(txt_color_picker)
txt_color_hex = txt_color_picker
back_ui_colored = edimg.color(back_ui, txt_color_hex)
img.paste(back_ui_colored, (0, 0), back_ui_colored)
match logo_radio:
case "tripleS":
logo = edimg.color('resource/triples_logo.png', txt_color_hex)
img.paste(logo, (61, 162), logo)
case "ARTMS":
logo = edimg.color('resource/artms_logo.png', txt_color_hex)
img.paste(logo, (61, 162), logo)
if member_name_dropdown:
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))
img.paste(img_name, (54, 466), img_name)
img_name_side = edimg.txt(member_name_dropdown, txt_color_r, txt_color_g, txt_color_b, 61, 270, "l")
img.paste(img_name_side, (932, 159),img_name_side)
if obj_num:
if obj_alphabet == "Other":
obj_alphabet = obj_alphabet_txt
img_obj_num_side = edimg.txt(obj_num+obj_alphabet, txt_color_r,txt_color_g,txt_color_b, 75, 270, "r")
img.paste(img_obj_num_side, (951, 448), img_obj_num_side)
if obj_serial:
img_obj_serial_side = edimg.serial(obj_serial, txt_color_r,txt_color_g,txt_color_b, 75)
img.paste(img_obj_serial_side, (943, 867), img_obj_serial_side)
match group_name_radio:
case "tripleS":
img_group_name_side = edimg.txt("tripleS", txt_color_r, txt_color_g, txt_color_b, 61, 270, "r")
img.paste(img_group_name_side, (943, 1238), img_group_name_side)
case "ARTMS":
img_group_name_side = edimg.color("resource/artms_side.png", txt_color_hex)
img.paste(img_group_name_side, (974, 1371), img_group_name_side)
case "Other":
img_group_name_side = edimg.txt(group_name_txt, txt_color_r, txt_color_g, txt_color_b, 61, 270, "r")
img.paste(img_group_name_side, (943, 1238), img_group_name_side)
group_name_radio = group_name_txt
match class_radio:
case "Zero" | "First" | "Double" | "Special":
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))
img.paste(img_class, (54, 700), img_class)
case "Other":
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))
img.paste(img_class, (54, 700), img_class)
match season_radio:
case "Atom01":
img_atom01 = edimg.color(atom01, txt_color_hex)
img.paste(img_atom01, (63, 951), img_atom01)
case "Binary01":
img_binary01 = edimg.color(binary01, txt_color_hex)
img.paste(img_binary01, (63, 951), img_binary01)
case "Cream01":
img_cream01 = edimg.color(cream01, txt_color_hex)
img.paste(img_cream01, (62, 950), img_cream01)
case "Divine01":
img_divine01 = edimg.color(divine01, txt_color_hex)
img.paste(img_divine01, (61, 951), img_divine01)
case "Other":
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))
x = edimg.calculate_size(season_txt, 130, "font/Helvetica_Neue_LT_Std_65_Medium.otf")
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))
img.paste(img_season,(60, 954), img_season)
img.paste(img_season_outline, (60 + x, 954), img_season_outline)
if sign != None:
sign = sign + 1
colored_icon = edimg.color(f'sign/{sign}.png', txt_color_hex)
if sign in sign_positions:
position = sign_positions[sign]
img.paste(colored_icon, position, colored_icon)
if qr_url_dropdown:
url_txt = fn.url_mapping(qr_url_dropdown)
img_qr = edimg.qr(url_txt)
match qr_Logo_radio:
case "tripleS":
img_qr_icon = edimg.qr_icon("resource/qr_icon_triples.png")
img_qr.paste(img_qr_icon, (126, 126), img_qr_icon)
img_qr = edimg.resize_img(img_qr, 335,335)
img.paste(img_qr, (555, 1098))
if right_btn:
img_right_modhaus = edimg.color(right_modhaus, txt_color_hex)
img.paste(img_right_modhaus, (61,1604), img_right_modhaus)
if rounded_back:
img = edimg.rounded(img)
krtime = fn.get_kr_time()
img_jpeg = img.convert('RGB')
img_jpeg.save(f'./data/cache/{member_name_dropdown}_{group_name_radio}_{class_radio}_{obj_num}{obj_alphabet}_{krtime}.jpg', quality=90)
return img, img
make_image_first = Image.open("resource/make_image_first.png")
def ex_gen(img_front, file_front_path, img_back, count, blur, blur_strength, watermark):
if img_back == None:
gr.Warning("Make two images, front and back")
return make_image_first, make_image_first
if img_front == None and file_front_path == None:
gr.Warning("Make two images, front and back")
return make_image_first, make_image_first
if file_front_path:
file_front = Image.open(file_front_path)
match count:
case "One File":
img_back = img_back.resize(file_front.size)
filename, _ = os.path.splitext(os.path.basename(file_front_path))
edimg.makegif(file_front, img_back)
return f"exgif.gif", img_back
case "Two Files":
return file_front, img_back
if blur:
img_front = img_front.filter(ImageFilter.GaussianBlur(blur_strength))
img_back = img_back.filter(ImageFilter.GaussianBlur(blur_strength))
if watermark:
img_txt = edimg.txt(watermark, 255, 255, 255, 210, 50, "l", "font/Helvetica_Neue_LT_Std_75_Bold.otf",(1338, 222), 120)
img_front.paste(img_txt, (65, 333), img_txt)
img_back.paste(img_txt, (65, 333), img_txt)
match count:
case "One File":
img = Image.new("RGBA", (2328, 1800), (0, 0, 0, 0))
img_front = edimg.rounded(img_front)
img_back = edimg.rounded(img_back)
img.paste(img_front, (0, 0), img_front)
img.paste(img_back, (1164, 0), img_back)
return img, img_blank
case "Two Files":
img_front = edimg.rounded(img_front)
img_back = edimg.rounded(img_back)
return img_front, img_back
|