Skip to content

Commit

Permalink
Merge LoadImageBatch into LoadImage
Browse files Browse the repository at this point in the history
  • Loading branch information
space-nuko committed Jun 2, 2023
1 parent 75dcbce commit 50d8044
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 45 deletions.
44 changes: 0 additions & 44 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,48 +1070,6 @@ def INPUT_TYPES(s):
}

class LoadImage:
@classmethod
def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
files = [f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f))]
return {"required":
{"image": (sorted(files), )},
}

CATEGORY = "image"

RETURN_TYPES = ("IMAGE", "MASK")
FUNCTION = "load_image"
def load_image(self, image):
image_path = folder_paths.get_annotated_filepath(image)
i = Image.open(image_path)
i = ImageOps.exif_transpose(i)
image = i.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
if 'A' in i.getbands():
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
mask = 1. - torch.from_numpy(mask)
else:
mask = torch.zeros((64,64), dtype=torch.float32, device="cpu")
return (image, mask)

@classmethod
def IS_CHANGED(s, image):
image_path = folder_paths.get_annotated_filepath(image)
m = hashlib.sha256()
with open(image_path, 'rb') as f:
m.update(f.read())
return m.digest().hex()

@classmethod
def VALIDATE_INPUTS(s, image):
if not folder_paths.exists_annotated_filepath(image):
return "Invalid image file: {}".format(image)

return True

class LoadImageBatch:
@classmethod
def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
Expand Down Expand Up @@ -1362,7 +1320,6 @@ def expand_image(self, image, left, top, right, bottom, feathering):
"PreviewImage": PreviewImage,
"LoadImage": LoadImage,
"LoadImageMask": LoadImageMask,
"LoadImageBatch": LoadImageBatch,
"ImageScale": ImageScale,
"ImageInvert": ImageInvert,
"ImagePadForOutpaint": ImagePadForOutpaint,
Expand Down Expand Up @@ -1444,7 +1401,6 @@ def expand_image(self, image, left, top, right, bottom, feathering):
"PreviewImage": "Preview Image",
"LoadImage": "Load Image",
"LoadImageMask": "Load Image (as Mask)",
"LoadImageBatch": "Load Image Batch",
"ImageScale": "Upscale Image",
"ImageUpscaleWithModel": "Upscale Image (using Model)",
"ImageInvert": "Invert Image",
Expand Down
1 change: 0 additions & 1 deletion web/extensions/core/uploadImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ app.registerExtension({
name: "Comfy.UploadImage",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
switch (nodeData.name) {
case "LoadImage":
case "LoadImageMask":
nodeData.input.required.upload = ["IMAGEUPLOAD"];
break;
Expand Down
5 changes: 5 additions & 0 deletions web/scripts/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ async function loadImageAsync(imageURL) {
}

const MULTIIMAGEUPLOAD = (node, inputName, inputData, app) => {
console.error("LOADDATA", node, inputName, inputData)
if (typeof inputData === "string") {
inputData = [inputData]
}

const imagesWidget = node.addWidget("text", inputName, inputData, () => {})
imagesWidget.disabled = true;

Expand Down

0 comments on commit 50d8044

Please sign in to comment.