v1.1.0 Update

- Added resize_method to the Multi Image Loader node for more resize options
- Added insert_mode which allows you to enter in seconds instead of frames on the LTX Sequencer node
- Updated workflows with more notes
- Re-added tiny vae to workflows
- Fixed various bugs
- more things i can't rememeber
This commit is contained in:
WhatDreamsCost
2026-03-24 19:45:16 -05:00
parent ecd00e6b40
commit cebc636192
8 changed files with 10111 additions and 1307 deletions

View File

@@ -1,9 +1,11 @@
import torch
import torch.nn.functional as F
import numpy as np
from PIL import Image, ImageOps
import os
import folder_paths
import io
import comfy.utils
class MultiImageLoader:
@classmethod
@@ -13,8 +15,9 @@ class MultiImageLoader:
"image_paths": ("STRING", {"default": "", "multiline": True}),
"width": ("INT", {"default": 0, "min": 0, "max": 8192, "step": 1}),
"height": ("INT", {"default": 0, "min": 0, "max": 8192, "step": 1}),
"upscale_method": (["lanczos", "bilinear", "nearest-exact"],),
"divisible_by": ("INT", {"default": 32, "min": 1, "max": 512, "step": 1}),
"interpolation": (["lanczos", "nearest", "bilinear", "bicubic", "area", "nearest-exact"],),
"resize_method": (["keep proportion", "stretch", "pad", "crop"],),
"multiple_of": ("INT", {"default": 0, "min": 0, "max": 512, "step": 1}),
"img_compression": ("INT", {"default": 18, "min": 0, "max": 100, "step": 1}),
},
}
@@ -25,13 +28,101 @@ class MultiImageLoader:
FUNCTION = "load_images"
CATEGORY = "image"
def load_images(self, image_paths, width, height, upscale_method, divisible_by, img_compression):
def resize_image(self, image, width, height, resize_method="keep proportion", interpolation="nearest", multiple_of=0):
MAX_RESOLUTION = 8192
_, oh, ow, _ = image.shape
x = y = x2 = y2 = 0
pad_left = pad_right = pad_top = pad_bottom = 0
if multiple_of > 1:
width = width - (width % multiple_of)
height = height - (height % multiple_of)
if resize_method == 'keep proportion' or resize_method == 'pad':
if width == 0 and oh < height:
width = MAX_RESOLUTION
elif width == 0 and oh >= height:
width = ow
if height == 0 and ow < width:
height = MAX_RESOLUTION
elif height == 0 and ow >= width:
height = oh
ratio = min(width / ow, height / oh)
new_width = round(ow * ratio)
new_height = round(oh * ratio)
if resize_method == 'pad':
pad_left = (width - new_width) // 2
pad_right = width - new_width - pad_left
pad_top = (height - new_height) // 2
pad_bottom = height - new_height - pad_top
width = new_width
height = new_height
elif resize_method == 'crop':
width = width if width > 0 else ow
height = height if height > 0 else oh
ratio = max(width / ow, height / oh)
new_width = round(ow * ratio)
new_height = round(oh * ratio)
x = (new_width - width) // 2
y = (new_height - height) // 2
x2 = x + width
y2 = y + height
if x2 > new_width:
x -= (x2 - new_width)
if x < 0:
x = 0
if y2 > new_height:
y -= (y2 - new_height)
if y < 0:
y = 0
width = new_width
height = new_height
else:
width = width if width > 0 else ow
height = height if height > 0 else oh
# Always apply resize logic
outputs = image.permute(0, 3, 1, 2)
if interpolation == "lanczos":
outputs = comfy.utils.lanczos(outputs, width, height)
else:
outputs = F.interpolate(outputs, size=(height, width), mode=interpolation)
if resize_method == 'pad':
if pad_left > 0 or pad_right > 0 or pad_top > 0 or pad_bottom > 0:
outputs = F.pad(outputs, (pad_left, pad_right, pad_top, pad_bottom), value=0)
outputs = outputs.permute(0, 2, 3, 1)
if resize_method == 'crop':
if x > 0 or y > 0 or x2 > 0 or y2 > 0:
outputs = outputs[:, y:y2, x:x2, :]
if multiple_of > 1 and (outputs.shape[2] % multiple_of != 0 or outputs.shape[1] % multiple_of != 0):
width = outputs.shape[2]
height = outputs.shape[1]
x = (width % multiple_of) // 2
y = (height % multiple_of) // 2
x2 = width - ((width % multiple_of) - x)
y2 = height - ((height % multiple_of) - y)
outputs = outputs[:, y:y2, x:x2, :]
outputs = torch.clamp(outputs, 0, 1)
return outputs
def load_images(self, image_paths, width, height, interpolation, resize_method, multiple_of, img_compression):
results = []
valid_paths = [p.strip() for p in image_paths.split("\n") if p.strip()]
# Track the dimensions of the first processed image
first_target_w, first_target_h = None, None
for path in valid_paths:
try:
# Resolve full path
@@ -43,49 +134,42 @@ class MultiImageLoader:
print(f"Warning: Image path not found: {path}")
continue
# Load image
image = Image.open(full_path)
image = ImageOps.exif_transpose(image)
image = image.convert("RGB")
orig_w, orig_h = image.size
target_w, target_h = width, height
if target_w == 0 and target_h == 0:
target_w, target_h = orig_w, orig_h
elif target_w == 0:
target_w = int(orig_w * (target_h / orig_h))
elif target_h == 0:
target_h = int(orig_h * (target_w / orig_w))
# Divisible by constraint
target_w = (target_w // divisible_by) * divisible_by
target_h = (target_h // divisible_by) * divisible_by
# To prevent torch.cat errors, ALL images in the batch must match the dimensions
# of the first successfully loaded image.
if first_target_w is None:
first_target_w, first_target_h = target_w, target_h
else:
target_w, target_h = first_target_w, first_target_h
if target_w != orig_w or target_h != orig_h:
resample = Image.LANCZOS if upscale_method == "lanczos" else Image.BILINEAR
image = image.resize((target_w, target_h), resample=resample)
# Compression
if img_compression > 0:
img_byte_arr = io.BytesIO()
image.save(img_byte_arr, format="JPEG", quality=max(1, 100 - img_compression))
image = Image.open(img_byte_arr)
# Convert to Torch Tensor to prepare for Advanced Resize Logic
image_np = np.array(image).astype(np.float32) / 255.0
results.append(torch.from_numpy(image_np)[None,])
image_tensor = torch.from_numpy(image_np)[None,]
# Apply Advanced Resize
image_tensor = self.resize_image(image_tensor, width, height, resize_method, interpolation, multiple_of)
# Compression (Applied after resize to accurately maintain the effect)
if img_compression > 0:
img_np = (image_tensor[0].numpy() * 255).clip(0, 255).astype(np.uint8)
img_pil = Image.fromarray(img_np)
img_byte_arr = io.BytesIO()
img_pil.save(img_byte_arr, format="JPEG", quality=max(1, 100 - img_compression))
img_pil = Image.open(img_byte_arr)
image_tensor = torch.from_numpy(np.array(img_pil).astype(np.float32) / 255.0)[None,]
results.append(image_tensor)
except Exception as e:
print(f"Error loading {path}: {e}")
# Combine all successfully loaded images into a single batched tensor for multi_output
if len(results) > 0:
multi_output = torch.cat(results, dim=0)
# Safety Check: Advanced resize methods might output differently sized tensors (e.g., 'keep proportion')
first_shape = results[0].shape
all_same_shape = all(r.shape == first_shape for r in results)
if all_same_shape:
multi_output = torch.cat(results, dim=0)
else:
print("MultiImageLoader Warning: Images have different dimensions due to resize settings. Cannot batch into multi_output. Outputting zero tensor for the batch, but individual output nodes will still work fine.")
multi_output = torch.zeros((1, 64, 64, 3))
else:
# Fallback empty tensor if no valid paths
multi_output = torch.zeros((1, 64, 64, 3))