Update app.py
Browse files
app.py
CHANGED
|
@@ -53,6 +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("RGBA", (canvas_width, canvas_height), (255, 255, 255, 0))
|
| 57 |
|
| 58 |
# Determine the relative size of the QR code based on the canvas dimensions
|
|
@@ -68,9 +69,9 @@ def resize_for_condition_image(input_image: Image.Image, resolution: int, canvas
|
|
| 68 |
qr_y = (canvas_height - H) // 2 # Center the QR code vertically
|
| 69 |
|
| 70 |
# Use the alpha channel of the input_image as the mask
|
| 71 |
-
canvas.paste(input_image, (qr_x, qr_y), input_image.split()[3]) # Alpha channel as mask
|
| 72 |
-
return canvas
|
| 73 |
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
SAMPLER_MAP = {
|
|
@@ -118,7 +119,7 @@ def inference(
|
|
| 118 |
)
|
| 119 |
qr.add_data(qr_code_content)
|
| 120 |
qr.make(fit=True)
|
| 121 |
-
|
| 122 |
qrcode_image = qr.make_image(fill_color="black", back_color=None).convert("RGBA")
|
| 123 |
qrcode_image = resize_for_condition_image(qrcode_image, 768, width, height)
|
| 124 |
else:
|
|
|
|
| 53 |
if canvas_height is None:
|
| 54 |
canvas_height = H
|
| 55 |
|
| 56 |
+
# Transparent canvas
|
| 57 |
canvas = Image.new("RGBA", (canvas_width, canvas_height), (255, 255, 255, 0))
|
| 58 |
|
| 59 |
# Determine the relative size of the QR code based on the canvas dimensions
|
|
|
|
| 69 |
qr_y = (canvas_height - H) // 2 # Center the QR code vertically
|
| 70 |
|
| 71 |
# Use the alpha channel of the input_image as the mask
|
| 72 |
+
canvas.paste(input_image, (qr_x, qr_y), mask=input_image.split()[3]) # Alpha channel as mask
|
|
|
|
| 73 |
|
| 74 |
+
return canvas
|
| 75 |
|
| 76 |
|
| 77 |
SAMPLER_MAP = {
|
|
|
|
| 119 |
)
|
| 120 |
qr.add_data(qr_code_content)
|
| 121 |
qr.make(fit=True)
|
| 122 |
+
|
| 123 |
qrcode_image = qr.make_image(fill_color="black", back_color=None).convert("RGBA")
|
| 124 |
qrcode_image = resize_for_condition_image(qrcode_image, 768, width, height)
|
| 125 |
else:
|