Skip to content

Commit

Permalink
fix: ⚡️ add missing controls to QRCode
Browse files Browse the repository at this point in the history
  • Loading branch information
melMass committed Jun 18, 2023
1 parent 811443b commit 7e86b0e
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions nodes/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,41 @@ def INPUT_TYPES(cls):
"INT",
{"default": 256, "max": 8096, "min": 0, "step": 1},
),
"error_correct": (("L", "M", "Q", "H"), {"default": "L"}),
"box_size": ("INT", {"default": 10, "max": 8096, "min": 0, "step": 1}),
"border": ("INT", {"default": 4, "max": 8096, "min": 0, "step": 1}),
"invert": (("True", "False"), {"default": "False"}),
}
}

RETURN_TYPES = ("IMAGE",)
FUNCTION = "do_qr"
CATEGORY = "fun"

def do_qr(self, url, width, height):
def do_qr(self, url, width, height,error_correct, box_size, border,invert):

if error_correct == "L" or error_correct not in ["M", "Q", "H"]:
error_correct = qrcode.constants.ERROR_CORRECT_L
elif error_correct == "M":
error_correct = qrcode.constants.ERROR_CORRECT_M
elif error_correct == "Q":
error_correct = qrcode.constants.ERROR_CORRECT_Q
else:
error_correct = qrcode.constants.ERROR_CORRECT_H

qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
error_correction=error_correct,
box_size=box_size,
border=border,
)
qr.add_data(url)
qr.make(fit=True)
# make the pil image
code = img = qr.make_image(back_color=(0, 0, 0), fill_color=(255, 255, 255))

back_color = (255, 255, 255) if invert == "True" else (0, 0, 0)
fill_color = (0, 0, 0) if invert == "True" else (255, 255, 255)

code = img = qr.make_image(back_color=back_color, fill_color=fill_color)

# that we now resize without filtering
code = code.resize((width, height), Image.NEAREST)
Expand Down

0 comments on commit 7e86b0e

Please sign in to comment.