make white qr code 50% transparent
Browse files
app.py
CHANGED
|
@@ -44,16 +44,15 @@ pipe.enable_xformers_memory_efficient_attention()
|
|
| 44 |
|
| 45 |
|
| 46 |
def resize_for_condition_image(input_image: Image.Image, resolution: int, canvas_width: int = None, canvas_height: int = None):
|
| 47 |
-
input_image = input_image.convert("RGBA")
|
| 48 |
W, H = input_image.size
|
| 49 |
|
| 50 |
-
# Create a blank canvas with the specified dimensions
|
| 51 |
if canvas_width is None:
|
| 52 |
canvas_width = W
|
| 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
|
|
@@ -74,6 +73,8 @@ def resize_for_condition_image(input_image: Image.Image, resolution: int, canvas
|
|
| 74 |
return canvas
|
| 75 |
|
| 76 |
|
|
|
|
|
|
|
| 77 |
SAMPLER_MAP = {
|
| 78 |
"DPM++ Karras SDE": lambda config: DPMSolverMultistepScheduler.from_config(config, use_karras=True, algorithm_type="sde-dpmsolver++"),
|
| 79 |
"DPM++ Karras": lambda config: DPMSolverMultistepScheduler.from_config(config, use_karras=True),
|
|
@@ -120,7 +121,16 @@ def inference(
|
|
| 120 |
qr.add_data(qr_code_content)
|
| 121 |
qr.make(fit=True)
|
| 122 |
|
| 123 |
-
qrcode_image = qr.make_image(fill_color="black", back_color=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
qrcode_image = resize_for_condition_image(qrcode_image, 768, width, height)
|
| 125 |
else:
|
| 126 |
print("Using QR Code Image")
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
def resize_for_condition_image(input_image: Image.Image, resolution: int, canvas_width: int = None, canvas_height: int = None):
|
| 47 |
+
input_image = input_image.convert("RGBA")
|
| 48 |
W, H = input_image.size
|
| 49 |
|
| 50 |
+
# Create a blank canvas with the specified dimensions and 50% transparent white background
|
| 51 |
if canvas_width is None:
|
| 52 |
canvas_width = W
|
| 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
|
|
|
|
| 73 |
return canvas
|
| 74 |
|
| 75 |
|
| 76 |
+
|
| 77 |
+
|
| 78 |
SAMPLER_MAP = {
|
| 79 |
"DPM++ Karras SDE": lambda config: DPMSolverMultistepScheduler.from_config(config, use_karras=True, algorithm_type="sde-dpmsolver++"),
|
| 80 |
"DPM++ Karras": lambda config: DPMSolverMultistepScheduler.from_config(config, use_karras=True),
|
|
|
|
| 121 |
qr.add_data(qr_code_content)
|
| 122 |
qr.make(fit=True)
|
| 123 |
|
| 124 |
+
qrcode_image = qr.make_image(fill_color="black", back_color="white").convert("RGBA")
|
| 125 |
+
|
| 126 |
+
# Add 50% transparency to the white background
|
| 127 |
+
data = qrcode_image.getdata()
|
| 128 |
+
new_data = [
|
| 129 |
+
(item[0], item[1], item[2], 128) if item[:3] == (255, 255, 255) else item
|
| 130 |
+
for item in data
|
| 131 |
+
]
|
| 132 |
+
qrcode_image.putdata(new_data)
|
| 133 |
+
|
| 134 |
qrcode_image = resize_for_condition_image(qrcode_image, 768, width, height)
|
| 135 |
else:
|
| 136 |
print("Using QR Code Image")
|