ginipick commited on
Commit
63d2006
Β·
verified Β·
1 Parent(s): d6ceac1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +108 -42
app.py CHANGED
@@ -7,16 +7,15 @@ from PIL import Image, ImageDraw
7
  from math import cos, sin, radians
8
 
9
  # ν…Œλ‘λ¦¬ μž₯식 ν•¨μˆ˜
10
- # create_border_decoration ν•¨μˆ˜ μˆ˜μ •
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 = 50 # Padding for decoration
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
- # Parse decoration prompt and draw accordingly
33
- if "flower" in decoration_prompt.lower():
34
- # 꽃 크기 μ„€μ •
35
- flower_size = 12
36
- gap = flower_size * 2 # 꽃 μ‚¬μ΄μ˜ 간격
 
 
 
 
 
37
 
38
- # ν…Œλ‘λ¦¬λ₯Ό 따라 μ λ“€μ˜ μœ„μΉ˜ 계산
39
- border_points = []
 
40
 
41
- # 상단 ν…Œλ‘λ¦¬
42
- for x in range(padding//2, new_width - padding//2, gap):
43
- border_points.append((x, padding//2))
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
- for x, y in border_points:
59
- # κ½ƒμžŽ 그리기 (8개의 κ½ƒμžŽ)
60
- petal_colors = ['pink', 'lightpink', 'peachpuff'] # λ‹€μ–‘ν•œ 색상 μ‚¬μš©
61
- for angle in range(0, 360, 45): # 8 petals
62
- x1 = x + flower_size * cos(radians(angle))
63
- y1 = y + flower_size * sin(radians(angle))
64
- petal_color = petal_colors[angle % len(petal_colors)]
65
- draw.ellipse([x1-4, y1-4, x1+4, y1+4], fill=petal_color)
66
-
67
- # 꽃 쀑심 그리기
68
  draw.ellipse([x-3, y-3, x+3, y+3], fill='yellow')
69
-
70
- # 잎 μΆ”κ°€ (선택적)
71
- if angle % 180 == 0: # μ–‘μͺ½μ— 잎 μΆ”κ°€
72
- draw.ellipse([x-8, y+8, x+8, y+16], fill='lightgreen')
73
- draw.ellipse([x-8, y-16, x+8, y-8], fill='lightgreen')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 μ½”λ“œ 데이터 포맷νŒ