Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,11 @@ 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,
|
|
|
|
|
|
|
|
|
10 |
# Get the size of the QR code image
|
11 |
width, height = qr_image.size
|
12 |
|
@@ -18,13 +22,14 @@ def create_border_decoration(qr_image, decoration_type="flowers"):
|
|
18 |
# Create new image with white background
|
19 |
decorated_image = Image.new('RGB', (new_width, new_height), 'white')
|
20 |
|
21 |
-
# Paste QR code in center
|
22 |
-
decorated_image.paste(qr_image, (padding, padding))
|
23 |
|
24 |
# Get draw object
|
25 |
draw = ImageDraw.Draw(decorated_image)
|
26 |
|
27 |
-
|
|
|
28 |
# Draw simple flower patterns in corners
|
29 |
corner_positions = [
|
30 |
(padding//2, padding//2), # Top-left
|
@@ -44,7 +49,14 @@ def create_border_decoration(qr_image, decoration_type="flowers"):
|
|
44 |
|
45 |
return decorated_image
|
46 |
|
47 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
def create_qr(
|
49 |
content,
|
50 |
qr_type,
|
@@ -53,7 +65,7 @@ def create_qr(
|
|
53 |
box_size,
|
54 |
border_size,
|
55 |
error_correction,
|
56 |
-
border_decoration="flowers" #
|
57 |
):
|
58 |
# QR ์ฝ๋ ๋ฐ์ดํฐ ํฌ๋งทํ
|
59 |
formatted_data = format_data(content, qr_type)
|
@@ -81,7 +93,7 @@ def create_qr(
|
|
81 |
qr_img = qr.make_image(fill_color=fill_color, back_color=back_color)
|
82 |
|
83 |
# Add border decoration if specified
|
84 |
-
if border_decoration
|
85 |
qr_img = create_border_decoration(qr_img, border_decoration)
|
86 |
|
87 |
# ํ์ผ ์ ์ฅ
|
|
|
6 |
from PIL import Image, ImageDraw
|
7 |
from math import cos, sin, radians
|
8 |
|
9 |
+
def create_border_decoration(qr_image, decoration_prompt="flowers"):
|
10 |
+
# Convert QR image to RGB if it's not
|
11 |
+
if qr_image.mode != 'RGB':
|
12 |
+
qr_image = qr_image.convert('RGB')
|
13 |
+
|
14 |
# Get the size of the QR code image
|
15 |
width, height = qr_image.size
|
16 |
|
|
|
22 |
# Create new image with white background
|
23 |
decorated_image = Image.new('RGB', (new_width, new_height), 'white')
|
24 |
|
25 |
+
# Paste QR code in center - now with explicit size
|
26 |
+
decorated_image.paste(qr_image, (padding, padding, padding + width, padding + height))
|
27 |
|
28 |
# Get draw object
|
29 |
draw = ImageDraw.Draw(decorated_image)
|
30 |
|
31 |
+
# Parse decoration prompt and draw accordingly
|
32 |
+
if "flower" in decoration_prompt.lower():
|
33 |
# Draw simple flower patterns in corners
|
34 |
corner_positions = [
|
35 |
(padding//2, padding//2), # Top-left
|
|
|
49 |
|
50 |
return decorated_image
|
51 |
|
52 |
+
# Inside create_interface(), update the border_decoration section:
|
53 |
+
border_decoration = gr.Textbox(
|
54 |
+
label="Border Decoration Prompt",
|
55 |
+
placeholder="Enter decoration style (e.g., flowers, simple, modern)",
|
56 |
+
value="flowers" # Default value
|
57 |
+
)
|
58 |
+
|
59 |
+
# Update the create_qr function:
|
60 |
def create_qr(
|
61 |
content,
|
62 |
qr_type,
|
|
|
65 |
box_size,
|
66 |
border_size,
|
67 |
error_correction,
|
68 |
+
border_decoration="flowers" # Default value
|
69 |
):
|
70 |
# QR ์ฝ๋ ๋ฐ์ดํฐ ํฌ๋งทํ
|
71 |
formatted_data = format_data(content, qr_type)
|
|
|
93 |
qr_img = qr.make_image(fill_color=fill_color, back_color=back_color)
|
94 |
|
95 |
# Add border decoration if specified
|
96 |
+
if border_decoration.strip(): # Only if decoration prompt is not empty
|
97 |
qr_img = create_border_decoration(qr_img, border_decoration)
|
98 |
|
99 |
# ํ์ผ ์ ์ฅ
|