ginipick commited on
Commit
a47b847
ยท
verified ยท
1 Parent(s): 6d9a769

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
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, decoration_type="flowers"):
 
 
 
 
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
- if decoration_type == "flowers":
 
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
- # QR ์ฝ”๋“œ ์ƒ์„ฑ์„ ์œ„ํ•œ ๋ฉ”์ธ ํ•จ์ˆ˜
 
 
 
 
 
 
 
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" # New parameter
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 != "none":
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
  # ํŒŒ์ผ ์ €์žฅ