Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,16 +7,15 @@ from PIL import Image, ImageDraw
|
|
7 |
from math import cos, sin, radians
|
8 |
|
9 |
# ν
λ리 μ₯μ ν¨μ
|
10 |
-
|
11 |
-
def create_border_decoration(qr_image, decoration_prompt="flowers"):
|
12 |
# Convert QR image to RGB mode first
|
13 |
qr_image = qr_image.convert('RGB')
|
14 |
|
15 |
# Get the size of the QR code image
|
16 |
width, height = qr_image.size
|
17 |
|
18 |
-
# Create a new image with padding for decoration
|
19 |
-
padding =
|
20 |
new_width = width + (padding * 2)
|
21 |
new_height = height + (padding * 2)
|
22 |
|
@@ -29,51 +28,118 @@ def create_border_decoration(qr_image, decoration_prompt="flowers"):
|
|
29 |
# Get draw object
|
30 |
draw = ImageDraw.Draw(decorated_image)
|
31 |
|
32 |
-
#
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
|
|
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
# μ°μΈ‘ ν
λ리
|
46 |
-
for y in range(padding//2, new_height - padding//2, gap):
|
47 |
-
border_points.append((new_width - padding//2, y))
|
48 |
-
|
49 |
-
# νλ¨ ν
λ리
|
50 |
-
for x in range(new_width - padding//2, padding//2, -gap):
|
51 |
-
border_points.append((x, new_height - padding//2))
|
52 |
-
|
53 |
-
# μ’μΈ‘ ν
λ리
|
54 |
-
for y in range(new_height - padding//2, padding//2, -gap):
|
55 |
-
border_points.append((padding//2, y))
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
draw.ellipse([x-3, y-3, x+3, y+3], fill='yellow')
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
return decorated_image
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
# QR μ½λ μμ± ν¨μ
|
78 |
def create_qr(content, qr_type, fill_color, back_color, box_size, border_size, error_correction, border_decoration="flowers"):
|
79 |
# QR μ½λ λ°μ΄ν° ν¬λ§·ν
|
|
|
7 |
from math import cos, sin, radians
|
8 |
|
9 |
# ν
λ리 μ₯μ ν¨μ
|
10 |
+
def create_border_decoration(qr_image, decoration_prompt="πΈ"):
|
|
|
11 |
# Convert QR image to RGB mode first
|
12 |
qr_image = qr_image.convert('RGB')
|
13 |
|
14 |
# Get the size of the QR code image
|
15 |
width, height = qr_image.size
|
16 |
|
17 |
+
# Create a new image with smaller padding for decoration
|
18 |
+
padding = 30 # ν¨λ©μ μ€μ¬μ QR μ½λ ν¬κΈ°λ₯Ό λ ν¬κ²
|
19 |
new_width = width + (padding * 2)
|
20 |
new_height = height + (padding * 2)
|
21 |
|
|
|
28 |
# Get draw object
|
29 |
draw = ImageDraw.Draw(decorated_image)
|
30 |
|
31 |
+
# μ΄λͺ¨μ§μ λ°λ₯Έ μ₯μ μ€μ
|
32 |
+
emoji_size = 12
|
33 |
+
gap = emoji_size * 2 # μ΄λͺ¨μ§ μ¬μ΄μ κ°κ²©
|
34 |
+
|
35 |
+
# ν
λ리λ₯Ό λ°λΌ μ λ€μ μμΉ κ³μ°
|
36 |
+
border_points = []
|
37 |
+
|
38 |
+
# μλ¨ ν
λ리
|
39 |
+
for x in range(padding//2, new_width - padding//2, gap):
|
40 |
+
border_points.append((x, padding//2))
|
41 |
|
42 |
+
# μ°μΈ‘ ν
λ리
|
43 |
+
for y in range(padding//2, new_height - padding//2, gap):
|
44 |
+
border_points.append((new_width - padding//2, y))
|
45 |
|
46 |
+
# νλ¨ ν
λ리
|
47 |
+
for x in range(new_width - padding//2, padding//2, -gap):
|
48 |
+
border_points.append((x, new_height - padding//2))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
# μ’μΈ‘ ν
λ리
|
51 |
+
for y in range(new_height - padding//2, padding//2, -gap):
|
52 |
+
border_points.append((padding//2, y))
|
53 |
+
|
54 |
+
# κ° μμΉμ μ΄λͺ¨μ§ 그리기
|
55 |
+
for x, y in border_points:
|
56 |
+
if "πΈ" in decoration_prompt: # λ²κ½
|
57 |
+
for angle in range(0, 360, 45):
|
58 |
+
x1 = x + emoji_size * cos(radians(angle))
|
59 |
+
y1 = y + emoji_size * sin(radians(angle))
|
60 |
+
draw.ellipse([x1-4, y1-4, x1+4, y1+4], fill='pink')
|
61 |
draw.ellipse([x-3, y-3, x+3, y+3], fill='yellow')
|
62 |
+
|
63 |
+
elif "π" in decoration_prompt: # λ€μν΄λ‘λ²
|
64 |
+
for angle in range(0, 360, 90):
|
65 |
+
x1 = x + emoji_size * cos(radians(angle))
|
66 |
+
y1 = y + emoji_size * sin(radians(angle))
|
67 |
+
draw.ellipse([x1-4, y1-4, x1+4, y1+4], fill='lightgreen')
|
68 |
+
draw.ellipse([x-2, y-2, x+2, y+2], fill='darkgreen')
|
69 |
+
|
70 |
+
elif "β" in decoration_prompt: # λ³
|
71 |
+
for angle in range(0, 360, 72):
|
72 |
+
x1 = x + emoji_size * cos(radians(angle))
|
73 |
+
y1 = y + emoji_size * sin(radians(angle))
|
74 |
+
draw.polygon([(x1, y1), (x1+4, y1+4), (x1-4, y1+4)], fill='gold')
|
75 |
+
|
76 |
+
elif "β€οΈ" in decoration_prompt: # ννΈ
|
77 |
+
draw.ellipse([x-6, y-6, x+6, y], fill='red')
|
78 |
+
draw.polygon([(x-6, y), (x+6, y), (x, y+8)], fill='red')
|
79 |
+
|
80 |
+
elif "π" in decoration_prompt: # λ°μ§μ΄λ λ³
|
81 |
+
for angle in range(0, 360, 45):
|
82 |
+
x1 = x + emoji_size * cos(radians(angle))
|
83 |
+
y1 = y + emoji_size * sin(radians(angle))
|
84 |
+
draw.line([(x, y), (x1, y1)], fill='yellow', width=2)
|
85 |
+
draw.ellipse([x-3, y-3, x+3, y+3], fill='white')
|
86 |
+
|
87 |
+
elif "π" in decoration_prompt: # μ
|
88 |
+
draw.ellipse([x-8, y-4, x+8, y+4], fill='lightgreen')
|
89 |
+
draw.ellipse([x-4, y-8, x+4, y+8], fill='green')
|
90 |
+
|
91 |
+
elif "π«" in decoration_prompt: # μμ©λμ΄
|
92 |
+
for i in range(5):
|
93 |
+
size = emoji_size - (i * 2)
|
94 |
+
angle = i * 45
|
95 |
+
x1 = x + size * cos(radians(angle))
|
96 |
+
y1 = y + size * sin(radians(angle))
|
97 |
+
draw.ellipse([x1-3, y1-3, x1+3, y1+3], fill='lightyellow')
|
98 |
+
|
99 |
+
elif "β¨" in decoration_prompt: # λ°μ§μ
|
100 |
+
for angle in range(0, 360, 60):
|
101 |
+
x1 = x + emoji_size * cos(radians(angle))
|
102 |
+
y1 = y + emoji_size * sin(radians(angle))
|
103 |
+
draw.line([(x, y), (x1, y1)], fill='gold', width=1)
|
104 |
+
|
105 |
+
elif "π" in decoration_prompt: # νλ
|
106 |
+
draw.arc([x-8, y-4, x+8, y+4], 0, 180, fill='lightblue')
|
107 |
+
draw.arc([x-8, y, x+8, y+8], 0, 180, fill='blue')
|
108 |
+
|
109 |
+
elif "π¨" in decoration_prompt: # 무μ§κ°
|
110 |
+
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']
|
111 |
+
for i, color in enumerate(colors):
|
112 |
+
size = emoji_size - (i * 2)
|
113 |
+
draw.arc([x-size, y-size, x+size, y+size], 0, 180, fill=color)
|
114 |
|
115 |
return decorated_image
|
116 |
|
117 |
+
# create_interface() ν¨μ λ΄μ border_decoration λΆλΆ μμ
|
118 |
+
border_decoration = gr.Dropdown(
|
119 |
+
choices=[
|
120 |
+
"πΈ Cherry Blossoms",
|
121 |
+
"π Four Leaf Clover",
|
122 |
+
"β Stars",
|
123 |
+
"β€οΈ Hearts",
|
124 |
+
"π Sparkles",
|
125 |
+
"π Leaves",
|
126 |
+
"π« Swirls",
|
127 |
+
"β¨ Twinkles",
|
128 |
+
"π Waves",
|
129 |
+
"π¨ Rainbow"
|
130 |
+
],
|
131 |
+
value="πΈ Cherry Blossoms",
|
132 |
+
label="Border Decoration Style"
|
133 |
+
)
|
134 |
+
|
135 |
+
# create_qr ν¨μμμ border_decoration μ²λ¦¬ μμ
|
136 |
+
def create_qr(..., border_decoration="πΈ Cherry Blossoms"):
|
137 |
+
...
|
138 |
+
if border_decoration.strip():
|
139 |
+
emoji = border_decoration.split()[0] # Get only the emoji part
|
140 |
+
qr_img = create_border_decoration(qr_img, emoji)
|
141 |
+
...
|
142 |
+
|
143 |
# QR μ½λ μμ± ν¨μ
|
144 |
def create_qr(content, qr_type, fill_color, back_color, box_size, border_size, error_correction, border_decoration="flowers"):
|
145 |
# QR μ½λ λ°μ΄ν° ν¬λ§·ν
|