ginipick commited on
Commit
3960520
ยท
verified ยท
1 Parent(s): e603970

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +104 -74
app.py CHANGED
@@ -6,7 +6,7 @@ from datetime import datetime
6
  from PIL import Image, ImageDraw
7
  from math import cos, sin, radians
8
 
9
- def create_border_decoration(qr_image, decoration_prompt="๐ŸŒธ"):
10
  # Convert QR image to RGB mode first
11
  qr_image = qr_image.convert('RGB')
12
 
@@ -27,9 +27,9 @@ def create_border_decoration(qr_image, decoration_prompt="๐ŸŒธ"):
27
  # Get draw object
28
  draw = ImageDraw.Draw(decorated_image)
29
 
30
- # ์ด๋ชจ์ง€์— ๋”ฐ๋ฅธ ์žฅ์‹ ์„ค์ •
31
- emoji_size = 12
32
- gap = emoji_size * 2 # ์ด๋ชจ์ง€ ์‚ฌ์ด์˜ ๊ฐ„๊ฒฉ
33
 
34
  # ํ…Œ๋‘๋ฆฌ๋ฅผ ๋”ฐ๋ผ ์ ๋“ค์˜ ์œ„์น˜ ๊ณ„์‚ฐ
35
  border_points = []
@@ -49,70 +49,97 @@ def create_border_decoration(qr_image, decoration_prompt="๐ŸŒธ"):
49
  # ์ขŒ์ธก ํ…Œ๋‘๋ฆฌ
50
  for y in range(new_height - padding//2, padding//2, -gap):
51
  border_points.append((padding//2, y))
52
-
53
- # ๊ฐ ์œ„์น˜์— ์ด๋ชจ์ง€ ๊ทธ๋ฆฌ๊ธฐ
54
  for x, y in border_points:
55
- if "๐ŸŒธ" in decoration_prompt: # ๋ฒš๊ฝƒ
 
56
  for angle in range(0, 360, 45):
57
- x1 = x + emoji_size * cos(radians(angle))
58
- y1 = y + emoji_size * sin(radians(angle))
59
  draw.ellipse([x1-4, y1-4, x1+4, y1+4], fill='pink')
 
60
  draw.ellipse([x-3, y-3, x+3, y+3], fill='yellow')
61
-
62
- elif "๐Ÿ€" in decoration_prompt: # ๋„ค์žŽํด๋กœ๋ฒ„
63
- for angle in range(0, 360, 90):
64
- x1 = x + emoji_size * cos(radians(angle))
65
- y1 = y + emoji_size * sin(radians(angle))
66
- draw.ellipse([x1-4, y1-4, x1+4, y1+4], fill='lightgreen')
67
- draw.ellipse([x-2, y-2, x+2, y+2], fill='darkgreen')
68
-
69
- elif "โญ" in decoration_prompt: # ๋ณ„
70
- for angle in range(0, 360, 72):
71
- x1 = x + emoji_size * cos(radians(angle))
72
- y1 = y + emoji_size * sin(radians(angle))
73
- draw.polygon([(x1, y1), (x1+4, y1+4), (x1-4, y1+4)], fill='gold')
74
-
75
- elif "โค๏ธ" in decoration_prompt: # ํ•˜ํŠธ
76
- draw.ellipse([x-6, y-6, x+6, y], fill='red')
77
- draw.polygon([(x-6, y), (x+6, y), (x, y+8)], fill='red')
78
-
79
- elif "๐ŸŒŸ" in decoration_prompt: # ๋ฐ˜์ง์ด๋Š” ๋ณ„
80
- for angle in range(0, 360, 45):
81
- x1 = x + emoji_size * cos(radians(angle))
82
- y1 = y + emoji_size * sin(radians(angle))
83
- draw.line([(x, y), (x1, y1)], fill='yellow', width=2)
84
- draw.ellipse([x-3, y-3, x+3, y+3], fill='white')
85
-
86
- elif "๐Ÿƒ" in decoration_prompt: # ์žŽ
87
- draw.ellipse([x-8, y-4, x+8, y+4], fill='lightgreen')
88
- draw.ellipse([x-4, y-8, x+4, y+8], fill='green')
89
-
90
- elif "๐Ÿ’ซ" in decoration_prompt: # ์†Œ์šฉ๋Œ์ด
91
  for i in range(5):
92
- size = emoji_size - (i * 2)
93
- angle = i * 45
94
- x1 = x + size * cos(radians(angle))
95
- y1 = y + size * sin(radians(angle))
96
- draw.ellipse([x1-3, y1-3, x1+3, y1+3], fill='lightyellow')
97
-
98
- elif "โœจ" in decoration_prompt: # ๋ฐ˜์ง์ž„
99
- for angle in range(0, 360, 60):
100
- x1 = x + emoji_size * cos(radians(angle))
101
- y1 = y + emoji_size * sin(radians(angle))
102
- draw.line([(x, y), (x1, y1)], fill='gold', width=1)
103
-
104
- elif "๐ŸŒŠ" in decoration_prompt: # ํŒŒ๋„
105
- draw.arc([x-8, y-4, x+8, y+4], 0, 180, fill='lightblue')
106
- draw.arc([x-8, y, x+8, y+8], 0, 180, fill='blue')
107
-
108
- elif "๐ŸŽจ" in decoration_prompt: # ๋ฌด์ง€๊ฐœ
109
- colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']
110
- for i, color in enumerate(colors):
111
- size = emoji_size - (i * 2)
112
- draw.arc([x-size, y-size, x+size, y+size], 0, 180, fill=color)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
  return decorated_image
115
 
 
 
116
  def create_qr(content, qr_type, fill_color, back_color, box_size, border_size, error_correction, border_decoration="๐ŸŒธ Cherry Blossoms"):
117
  # QR ์ฝ”๋“œ ๋ฐ์ดํ„ฐ ํฌ๋งทํŒ…
118
  formatted_data = format_data(content, qr_type)
@@ -202,7 +229,7 @@ def format_example_text(qr_type):
202
  }
203
  return examples.get(qr_type, "Enter your content here...")
204
 
205
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
206
  def create_interface():
207
  theme = gr.themes.Soft(
208
  primary_hue="blue",
@@ -214,6 +241,8 @@ def create_interface():
214
  )
215
 
216
  with gr.Blocks(theme=theme, title="QR Canvas") as demo:
 
 
217
  gr.Markdown(
218
  """
219
  # ๐ŸŽฏ QR CANVAS
@@ -282,24 +311,25 @@ def create_interface():
282
  value="Medium (15%)",
283
  label="Error Correction Level"
284
  )
285
-
286
  border_decoration = gr.Dropdown(
287
  choices=[
288
- "๐ŸŒธ Cherry Blossoms",
289
- "๐Ÿ€ Four Leaf Clover",
290
- "โญ Stars",
291
- "โค๏ธ Hearts",
292
- "๐ŸŒŸ Sparkles",
293
- "๐Ÿƒ Leaves",
294
- "๐Ÿ’ซ Swirls",
295
- "โœจ Twinkles",
296
- "๐ŸŒŠ Waves",
297
- "๐ŸŽจ Rainbow"
298
  ],
299
- value="๐ŸŒธ Cherry Blossoms",
300
  label="Border Decoration Style"
301
  )
302
-
 
303
  generate_btn = gr.Button(
304
  "Generate QR Code",
305
  variant="primary"
 
6
  from PIL import Image, ImageDraw
7
  from math import cos, sin, radians
8
 
9
+ def create_border_decoration(qr_image, decoration_style="Flowers"):
10
  # Convert QR image to RGB mode first
11
  qr_image = qr_image.convert('RGB')
12
 
 
27
  # Get draw object
28
  draw = ImageDraw.Draw(decorated_image)
29
 
30
+ # ์žฅ์‹ ํฌ๊ธฐ ์„ค์ •
31
+ deco_size = 12
32
+ gap = deco_size * 2 # ์žฅ์‹ ์‚ฌ์ด์˜ ๊ฐ„๊ฒฉ
33
 
34
  # ํ…Œ๋‘๋ฆฌ๋ฅผ ๋”ฐ๋ผ ์ ๋“ค์˜ ์œ„์น˜ ๊ณ„์‚ฐ
35
  border_points = []
 
49
  # ์ขŒ์ธก ํ…Œ๋‘๋ฆฌ
50
  for y in range(new_height - padding//2, padding//2, -gap):
51
  border_points.append((padding//2, y))
52
+
53
+ # ๊ฐ ์Šคํƒ€์ผ์— ๋”ฐ๋ฅธ ์žฅ์‹ ๊ทธ๋ฆฌ๊ธฐ
54
  for x, y in border_points:
55
+ if decoration_style == "Flowers": # ๊ฝƒ ํŒจํ„ด
56
+ # ๊ฝƒ์žŽ
57
  for angle in range(0, 360, 45):
58
+ x1 = x + deco_size * cos(radians(angle))
59
+ y1 = y + deco_size * sin(radians(angle))
60
  draw.ellipse([x1-4, y1-4, x1+4, y1+4], fill='pink')
61
+ # ๊ฝƒ ์ค‘์‹ฌ
62
  draw.ellipse([x-3, y-3, x+3, y+3], fill='yellow')
63
+
64
+ elif decoration_style == "Hearts": # ํ•˜ํŠธ ํŒจํ„ด
65
+ # ์ž‘์€ ํ•˜ํŠธ๋“ค์„ ์—ฐ์†์œผ๋กœ ๊ทธ๋ฆฌ๊ธฐ
66
+ heart_size = 6
67
+ draw.ellipse([x-heart_size, y-heart_size, x, y], fill='red')
68
+ draw.ellipse([x, y-heart_size, x+heart_size, y], fill='red')
69
+ draw.polygon([(x-heart_size, y), (x+heart_size, y), (x, y+heart_size)], fill='red')
70
+
71
+ elif decoration_style == "Waves": # ์›จ์ด๋ธŒ ํŒจํ„ด
72
+ wave_size = 10
73
+ draw.arc([x-wave_size, y-wave_size//2, x+wave_size, y+wave_size//2],
74
+ 0, 180, fill='lightblue', width=2)
75
+ draw.arc([x-wave_size, y, x+wave_size, y+wave_size],
76
+ 0, 180, fill='blue', width=2)
77
+
78
+ elif decoration_style == "Leaves": # ์žŽ ํŒจํ„ด
79
+ leaf_size = 8
80
+ # ๋ฉ”์ธ ์žŽ
81
+ draw.ellipse([x-leaf_size, y-leaf_size//2, x+leaf_size, y+leaf_size//2],
82
+ fill='lightgreen')
83
+ # ์ž‘์€ ์žŽ
84
+ draw.ellipse([x-leaf_size//2, y-leaf_size, x+leaf_size//2, y+leaf_size],
85
+ fill='darkgreen')
86
+
87
+ elif decoration_style == "Stars": # ๋ณ„ ํŒจํ„ด
88
+ star_size = 6
89
+ points = []
 
 
 
90
  for i in range(5):
91
+ angle = i * 72
92
+ # ์™ธ๊ณฝ ์ 
93
+ x1 = x + star_size * cos(radians(angle))
94
+ y1 = y + star_size * sin(radians(angle))
95
+ points.append((x1, y1))
96
+ # ๋‚ด๋ถ€ ์ 
97
+ x2 = x + (star_size/2) * cos(radians(angle + 36))
98
+ y2 = y + (star_size/2) * sin(radians(angle + 36))
99
+ points.append((x2, y2))
100
+ draw.polygon(points, fill='gold')
101
+
102
+ elif decoration_style == "Chains": # ์ฒด์ธ ํŒจํ„ด
103
+ chain_size = 8
104
+ draw.ellipse([x-chain_size, y-chain_size//2, x+chain_size, y+chain_size//2],
105
+ outline='gray', width=2)
106
+
107
+ elif decoration_style == "Bubbles": # ๋ฒ„๋ธ” ํŒจํ„ด
108
+ bubble_sizes = [6, 4, 2]
109
+ for size in bubble_sizes:
110
+ draw.ellipse([x-size, y-size, x+size, y+size],
111
+ outline='skyblue', width=1)
112
+
113
+ elif decoration_style == "Vines": # ๋ฉ๊ตด ํŒจํ„ด
114
+ vine_size = 10
115
+ # ๋ฉ”์ธ ๋ฉ๊ตด
116
+ draw.arc([x-vine_size, y-vine_size, x+vine_size, y+vine_size],
117
+ 0, 180, fill='green', width=2)
118
+ # ์ž‘์€ ์žŽ
119
+ draw.ellipse([x-3, y-3, x+3, y+3], fill='lightgreen')
120
+
121
+ elif decoration_style == "Diamonds": # ๋‹ค์ด์•„๋ชฌ๋“œ ํŒจํ„ด
122
+ diamond_size = 6
123
+ points = [
124
+ (x, y-diamond_size), # ์ƒ๋‹จ
125
+ (x+diamond_size, y), # ์šฐ์ธก
126
+ (x, y+diamond_size), # ํ•˜๋‹จ
127
+ (x-diamond_size, y) # ์ขŒ์ธก
128
+ ]
129
+ draw.polygon(points, outline='purple', width=1)
130
+
131
+ elif decoration_style == "Lace": # ๋ ˆ์ด์Šค ํŒจํ„ด
132
+ lace_size = 8
133
+ # ๋ ˆ์ด์Šค ์›ํ˜• ํŒจํ„ด
134
+ draw.arc([x-lace_size, y-lace_size, x+lace_size, y+lace_size],
135
+ 0, 180, fill='gray', width=1)
136
+ draw.arc([x-lace_size//2, y-lace_size//2, x+lace_size//2, y+lace_size//2],
137
+ 180, 360, fill='gray', width=1)
138
 
139
  return decorated_image
140
 
141
+
142
+
143
  def create_qr(content, qr_type, fill_color, back_color, box_size, border_size, error_correction, border_decoration="๐ŸŒธ Cherry Blossoms"):
144
  # QR ์ฝ”๋“œ ๋ฐ์ดํ„ฐ ํฌ๋งทํŒ…
145
  formatted_data = format_data(content, qr_type)
 
229
  }
230
  return examples.get(qr_type, "Enter your content here...")
231
 
232
+
233
  def create_interface():
234
  theme = gr.themes.Soft(
235
  primary_hue="blue",
 
241
  )
242
 
243
  with gr.Blocks(theme=theme, title="QR Canvas") as demo:
244
+
245
+
246
  gr.Markdown(
247
  """
248
  # ๐ŸŽฏ QR CANVAS
 
311
  value="Medium (15%)",
312
  label="Error Correction Level"
313
  )
314
+
315
  border_decoration = gr.Dropdown(
316
  choices=[
317
+ "Flowers", # ๊ฝƒ ํŒจํ„ด
318
+ "Hearts", # ํ•˜ํŠธ ํŒจํ„ด
319
+ "Waves", # ์›จ์ด๋ธŒ ํŒจํ„ด
320
+ "Leaves", # ์žŽ ํŒจํ„ด
321
+ "Stars", # ๋ณ„ ํŒจํ„ด
322
+ "Chains", # ์ฒด์ธ ํŒจํ„ด
323
+ "Bubbles", # ๋ฒ„๋ธ” ํŒจํ„ด
324
+ "Vines", # ๋ฉ๊ตด ํŒจํ„ด
325
+ "Diamonds", # ๋‹ค์ด์•„๋ชฌ๋“œ ํŒจํ„ด
326
+ "Lace" # ๋ ˆ์ด์Šค ํŒจํ„ด
327
  ],
328
+ value="Flowers",
329
  label="Border Decoration Style"
330
  )
331
+
332
+
333
  generate_btn = gr.Button(
334
  "Generate QR Code",
335
  variant="primary"