new node, minor fixes

Added a image manipulation tool node, uses PIL. Also made the loader be able to use baked in Vae
This commit is contained in:
chibiace
2023-10-16 21:46:20 +13:00
committed by GitHub
parent 4ee95b72b3
commit 3689fc62a3
2 changed files with 67 additions and 7 deletions
+67 -7
View File
@@ -1,9 +1,12 @@
import torch
import folder_paths
import comfy.sd
import comfy.utils
from PIL import Image, ImageOps
import numpy as np
### GLOBALS ###
MAX_RESOLUTION=8192
MAX_RESOLUTION=32768
class Loader:
@@ -14,7 +17,7 @@ class Loader:
def INPUT_TYPES(s):
return {"required":{
"Checkpoint": (folder_paths.get_filename_list("checkpoints"), ),
"Vae": (folder_paths.get_filename_list("vae"), ),
"Vae": (["Included"] + folder_paths.get_filename_list("vae"), ),
"stop_at_clip_layer": ("INT", {"default": -1, "min": -24, "max": -1, "step": 1}),
"width": ("INT", {"default": 512, "min": 16, "max": MAX_RESOLUTION, "step": 8}),
"height": ("INT", {"default": 512, "min": 16, "max": MAX_RESOLUTION, "step": 8}),
@@ -27,10 +30,16 @@ class Loader:
def loader(self, Checkpoint,Vae,stop_at_clip_layer,width,height,batch_size):
ckpt_path = folder_paths.get_full_path("checkpoints", Checkpoint)
ckpt = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=False, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings"))
output_vae = False
if Vae == "Included":
output_vae = True
ckpt = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=output_vae, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings"))
vae_path = folder_paths.get_full_path("vae", Vae)
vae = comfy.sd.VAE(ckpt_path=vae_path)
if Vae == "Included":
vae = ckpt[:3][2]
else:
vae_path = folder_paths.get_full_path("vae", Vae)
vae = comfy.sd.VAE(ckpt_path=vae_path)
clip = ckpt[:3][1].clone()
clip.clip_layer(stop_at_clip_layer)
@@ -69,9 +78,60 @@ class Prompts:
return ([[pos_cond, {"pooled_output": pos_pooled}]],[[neg_cond, {"pooled_output": neg_pooled}]],)
class ImageTool:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("IMAGE",),
"width": ("INT", {"default": 1920, "min": 16, "max": MAX_RESOLUTION, "step": 1}),
"height": ("INT", {"default": 1080, "min": 16, "max": MAX_RESOLUTION, "step": 1}),
"crop": ([False,True],),
"rotate": ("INT", {"default": 0, "min": 0, "max": 360, "step": 1}),
"mirror": ([False,True],),
"flip":([False,True],),
"bgcolor": (["black","white"],),
},
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "imagetools"
CATEGORY = "Chibi-Nodes"
def imagetools(self, image, height, width, crop, rotate, mirror, flip, bgcolor):
image = Image.fromarray(np.clip(255. * image[0].cpu().numpy(),0,255).astype(np.uint8))
image = image.rotate(rotate,fillcolor=bgcolor)
if mirror:
image = ImageOps.mirror(image)
if flip:
image = ImageOps.flip(image)
if crop:
im_width, im_height = image.size
left = (im_width - width)/2
top = (im_height - height)/2
right = (im_width + width)/2
bottom = (im_height + height)/2
image = image.crop((left, top, right, bottom))
else:
image = image.resize((width,height), Image.Resampling.LANCZOS)
image = ImageOps.exif_transpose(image)
image = image.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
return(image,)
NODE_CLASS_MAPPINGS = {
"Loader":Loader,
"Prompts": Prompts
"Prompts": Prompts,
"ImageTool": ImageTool,
}
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 88 KiB