Skip to content

Commit

Permalink
Add a LoadImage node to load images for img2img.
Browse files Browse the repository at this point in the history
  • Loading branch information
comfyanonymous committed Jan 22, 2023
1 parent 220afe3 commit 15f8da2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Binary file added input/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def INPUT_TYPES(s):
FUNCTION = "encode"

def encode(self, vae, pixels):
x = (pixels.shape[1] // 64) * 64
y = (pixels.shape[2] // 64) * 64
if pixels.shape[1] != x or pixels.shape[2] != y:
pixels = pixels[:,:x,:y,:]
return (vae.encode(pixels), )

class CheckpointLoader:
Expand Down Expand Up @@ -205,6 +209,24 @@ def save_images(self, images, prompt=None, extra_pnginfo=None):
img.save(f"output/ComfyUI_{self.counter:05}_.png", pnginfo=metadata, optimize=True)
self.counter += 1

class LoadImage:
input_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "input")
@classmethod
def INPUT_TYPES(s):
return {"required":
{"image": (os.listdir(s.input_dir), )},
}

RETURN_TYPES = ("IMAGE",)
FUNCTION = "load_image"
def load_image(self, image):
image_path = os.path.join(self.input_dir, image)
image = Image.open(image_path).convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image[None])[None,]
return image



NODE_CLASS_MAPPINGS = {
"KSampler": KSampler,
Expand All @@ -216,6 +238,7 @@ def save_images(self, images, prompt=None, extra_pnginfo=None):
"EmptyLatentImage": EmptyLatentImage,
"LatentUpscale": LatentUpscale,
"SaveImage": SaveImage,
"LoadImage": LoadImage
}


0 comments on commit 15f8da2

Please sign in to comment.