Add transparency support for QR code
Browse files
app.py
CHANGED
@@ -53,7 +53,7 @@ def resize_for_condition_image(input_image: Image.Image, resolution: int, canvas
|
|
53 |
if canvas_height is None:
|
54 |
canvas_height = H
|
55 |
|
56 |
-
canvas = Image.new("
|
57 |
|
58 |
# Determine the relative size of the QR code based on the canvas dimensions
|
59 |
qr_scale_ratio = 768 / min(1024, 768) # Base ratio (relative to 1024x768)
|
@@ -66,7 +66,7 @@ def resize_for_condition_image(input_image: Image.Image, resolution: int, canvas
|
|
66 |
# Paste the resized QR code 2/3rds of the way over the canvas
|
67 |
qr_x = int(canvas_width * (2 / 3)) - (W // 2) # Adjust x-coordinate to 2/3 of the canvas
|
68 |
qr_y = (canvas_height - H) // 2 # Center the QR code vertically
|
69 |
-
canvas.paste(input_image, (qr_x, qr_y))
|
70 |
return canvas
|
71 |
|
72 |
|
@@ -116,8 +116,8 @@ def inference(
|
|
116 |
)
|
117 |
qr.add_data(qr_code_content)
|
118 |
qr.make(fit=True)
|
119 |
-
|
120 |
-
qrcode_image = qr.make_image(fill_color="black", back_color="
|
121 |
qrcode_image = resize_for_condition_image(qrcode_image, 768, width, height)
|
122 |
else:
|
123 |
print("Using QR Code Image")
|
|
|
53 |
if canvas_height is None:
|
54 |
canvas_height = H
|
55 |
|
56 |
+
canvas = Image.new("RGBA", (canvas_width, canvas_height), (255, 255, 255, 0))
|
57 |
|
58 |
# Determine the relative size of the QR code based on the canvas dimensions
|
59 |
qr_scale_ratio = 768 / min(1024, 768) # Base ratio (relative to 1024x768)
|
|
|
66 |
# Paste the resized QR code 2/3rds of the way over the canvas
|
67 |
qr_x = int(canvas_width * (2 / 3)) - (W // 2) # Adjust x-coordinate to 2/3 of the canvas
|
68 |
qr_y = (canvas_height - H) // 2 # Center the QR code vertically
|
69 |
+
canvas.paste(input_image, (qr_x, qr_y), input_image)
|
70 |
return canvas
|
71 |
|
72 |
|
|
|
116 |
)
|
117 |
qr.add_data(qr_code_content)
|
118 |
qr.make(fit=True)
|
119 |
+
|
120 |
+
qrcode_image = qr.make_image(fill_color="black", back_color=None).convert("RGBA")
|
121 |
qrcode_image = resize_for_condition_image(qrcode_image, 768, width, height)
|
122 |
else:
|
123 |
print("Using QR Code Image")
|