Update app.py
Browse files
app.py
CHANGED
@@ -13,33 +13,27 @@ def generate_qr_code(url, title):
|
|
13 |
buffer = io.BytesIO()
|
14 |
qr.png(buffer, scale=10)
|
15 |
|
16 |
-
# Move to the beginning of the StringIO buffer
|
17 |
buffer.seek(0)
|
18 |
qr_image = Image.open(buffer)
|
19 |
|
20 |
-
# Prepare to add title to the image
|
21 |
image_width = qr_image.width
|
22 |
-
image_height = qr_image.height +
|
23 |
-
|
24 |
-
# Create a new image with white background
|
25 |
result_image = Image.new('RGB', (image_width, image_height), 'white')
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
# Draw the title on the image
|
30 |
draw = ImageDraw.Draw(result_image)
|
31 |
-
font = ImageFont.truetype("dejavu-sans-bold.ttf", 24)
|
32 |
-
|
33 |
-
#
|
34 |
text_width, text_height = draw.textsize(title, font=font)
|
35 |
-
|
36 |
-
# Calculate the text's position (centered)
|
37 |
text_x = (image_width - text_width) // 2
|
38 |
-
text_y =
|
39 |
-
|
40 |
-
|
41 |
-
return result_image
|
42 |
|
|
|
43 |
|
44 |
|
45 |
# Create the Gradio interface
|
|
|
13 |
buffer = io.BytesIO()
|
14 |
qr.png(buffer, scale=10)
|
15 |
|
|
|
16 |
buffer.seek(0)
|
17 |
qr_image = Image.open(buffer)
|
18 |
|
|
|
19 |
image_width = qr_image.width
|
20 |
+
image_height = qr_image.height + 100 # add space for text
|
21 |
+
|
|
|
22 |
result_image = Image.new('RGB', (image_width, image_height), 'white')
|
23 |
+
result_image.paste(qr_image, (0, 100))
|
24 |
+
|
|
|
|
|
25 |
draw = ImageDraw.Draw(result_image)
|
26 |
+
font = ImageFont.truetype("dejavu-sans-bold.ttf", 24)
|
27 |
+
|
28 |
+
# Here we use `textsize`
|
29 |
text_width, text_height = draw.textsize(title, font=font)
|
30 |
+
|
|
|
31 |
text_x = (image_width - text_width) // 2
|
32 |
+
text_y = 30 # Adjust vertical position
|
33 |
+
|
34 |
+
draw.text((text_x, text_y), title, fill="black", font=font)
|
|
|
35 |
|
36 |
+
return result_image
|
37 |
|
38 |
|
39 |
# Create the Gradio interface
|