Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions MaskNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,11 +1111,13 @@ def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING", {"multiline": True}),
"resize": (["Scale", "Pad", "None"], {"default": "Scale"}),
"size": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}),
"qr_version": ("INT", {"default": 1, "min": 1, "max": 40, "step": 1}),
"error_correction": (["L", "M", "Q", "H"], {"default": "H"}),
"box_size": ("INT", {"default": 10, "min": 1, "max": 100, "step": 1}),
"border": ("INT", {"default": 4, "min": 0, "max": 100, "step": 1}),
"pad_color": (["White", "Grey", "Black"], {"default": "White"}),
},
}

Expand All @@ -1124,7 +1126,7 @@ def INPUT_TYPES(cls):

CATEGORY = "Masquerade Nodes"

def create_qr_code(self, text, size, qr_version, error_correction, box_size, border):
def create_qr_code(self, text, resize, size, qr_version, error_correction, box_size, border, pad_color):
ensure_package("qrcode")
import qrcode
if error_correction =="L":
Expand All @@ -1144,9 +1146,18 @@ def create_qr_code(self, text, size, qr_version, error_correction, box_size, bor
qr.add_data(text)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
img = img.resize((size,size))
if resize == "Scale":
img = img.resize((size, size))
# Convert img (a PIL Image) into a torch tensor
tensor = torch.from_numpy(np.array(img))
tensor = torch.from_numpy(np.array(img)).float()

if resize == "Pad":
# if the size is larger then pad
if tensor.shape[1] < size:
padding = (size - tensor.shape[1]) // 2
color = {"White": 1.0, "Grey": 0.5, "Black": 0.0}.get(pad_color, 0)
tensor = torchfn.pad(tensor, [padding, padding, padding, padding], value=color)

return (tensor2rgb(tensor.unsqueeze(0)),)

def rgb2hsv(rgb):
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,13 @@ This node is the same as Unary Mask Op, but will operate across all channels of
## Create QR Code
#### Inputs
* `text` - The content to embed in the QR Code
* `resize` - how to resize 'Scale' will scale the qr code, 'Pad' will pad if the qr code is smaller then the size, 'None' will do nothing.
* `size` - The size of the QR Code (across height and width) in pixels.
* `qr_version` - The version of QR Code to use. Higher versions can encode more data, but are larger.
* `error_correction` - The level of error correction to use.
* `box_size` - The size of each box in the QR Code in pixels.
* `border` - The size of the border around the QR Code in pixels.
* `pad_color` - The color to pad with, 'White', 'Grey', 'Black'

## Convert Color Space
#### Inputs
Expand Down
Loading