mirror of
https://github.com/justUmen/Bjornulf_custom_nodes.git
synced 2026-09-21 10:51:26 -03:00
Add some more nodes
This commit is contained in:
@@ -20,7 +20,9 @@ from .show_int import ShowInt
|
||||
from .show_float import ShowFloat
|
||||
from .save_text import SaveText
|
||||
from .save_tmp_image import SaveTmpImage
|
||||
from .save_image_path import SaveImagePath
|
||||
from .save_api_image import SaveApiImage
|
||||
from .resize_image import ResizeImage
|
||||
from .loop_my_combos_samplers_schedulers import LoopCombosSamplersSchedulers
|
||||
|
||||
# from .CUSTOM_STRING import CustomStringType
|
||||
@@ -37,7 +39,9 @@ NODE_CLASS_MAPPINGS = {
|
||||
"Bjornulf_ShowInt": ShowInt,
|
||||
"Bjornulf_ShowFloat": ShowFloat,
|
||||
"Bjornulf_SaveText": SaveText,
|
||||
"Bjornulf_ResizeImage": ResizeImage,
|
||||
"Bjornulf_SaveTmpImage": SaveTmpImage,
|
||||
"Bjornulf_SaveImagePath": SaveImagePath,
|
||||
"Bjornulf_SaveApiImage": SaveApiImage,
|
||||
"Bjornulf_CombineTexts": CombineTexts,
|
||||
"Bjornulf_LoopTexts": LoopTexts,
|
||||
@@ -59,6 +63,8 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"Bjornulf_ShowText": "👁 Show (Text)",
|
||||
"Bjornulf_ShowInt": "👁 Show (Int)",
|
||||
"Bjornulf_ShowFloat": "👁 Show (Float)",
|
||||
"Bjornulf_ResizeImage": "📏 Resize Image",
|
||||
"Bjornulf_SaveImagePath": "🖼 Save Image (exact path, exact name)",
|
||||
"Bjornulf_SaveTmpImage": "🖼 Save Image (tmp_api.png)",
|
||||
"Bjornulf_SaveApiImage": "🖼 Save Image (API_IMAGES/00001.png...)",
|
||||
"Bjornulf_SaveText": "💾 Save Text", #Make SaveCharacter, SaveLocation, SaveCamera, SaveAction, SaveClothes, SaveEmotion...
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,43 @@
|
||||
import numpy as np
|
||||
import torch
|
||||
from PIL import Image
|
||||
|
||||
class ResizeImage:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"image": ("IMAGE", {}),
|
||||
"width": ("INT", {"default": 256}),
|
||||
"height": ("INT", {"default": 256}),
|
||||
}
|
||||
}
|
||||
|
||||
FUNCTION = "resize_image"
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
OUTPUT_NODE = True
|
||||
CATEGORY = "Bjornulf"
|
||||
|
||||
def resize_image(self, image, width=256, height=256):
|
||||
# Convert the image from ComfyUI format to PIL Image
|
||||
i = 255. * image.cpu().numpy()
|
||||
|
||||
# Reshape the image if it's not in the expected format, remove any leading dimensions of size 1
|
||||
if i.ndim > 3:
|
||||
i = np.squeeze(i)
|
||||
# Ensure the image is 3D (height, width, channels)
|
||||
if i.ndim == 2:
|
||||
i = i[:, :, np.newaxis] # Add a channel dimension if it's missing
|
||||
|
||||
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
|
||||
|
||||
# Resize the image
|
||||
img_resized = img.resize((width, height), Image.LANCZOS)
|
||||
|
||||
# Convert the PIL image back to numpy array
|
||||
img_resized_np = np.array(img_resized).astype(np.float32) / 255.0
|
||||
|
||||
# Assuming ComfyUI format needs the image back in tensor format, convert it back
|
||||
img_resized_tensor = torch.tensor(img_resized_np)
|
||||
|
||||
return (img_resized_tensor, )
|
||||
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
class SaveImagePath:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"image": ("IMAGE", {"forceInput": True}),
|
||||
"path": ("STRING", {"default":"./output/default.png"}), # Add path input
|
||||
}
|
||||
}
|
||||
|
||||
FUNCTION = "save_image_path"
|
||||
RETURN_TYPES = ()
|
||||
OUTPUT_NODE = True
|
||||
CATEGORY = "Bjornulf"
|
||||
|
||||
def save_image_path(self, image, path):
|
||||
# Ensure the output directory exists
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
|
||||
# Convert the image from ComfyUI format to PIL Image
|
||||
i = 255. * image.cpu().numpy()
|
||||
|
||||
# Reshape the image if it's not in the expected format, remove any leading dimensions of size 1
|
||||
if i.ndim > 3:
|
||||
i = np.squeeze(i)
|
||||
# Ensure the image is 3D (height, width, channels)
|
||||
if i.ndim == 2:
|
||||
i = i[:, :, np.newaxis] # Add a channel dimension if it's missing
|
||||
|
||||
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
|
||||
|
||||
# Save the image, overwriting if it exists
|
||||
img.save(path, format="PNG")
|
||||
|
||||
return ()
|
||||
Reference in New Issue
Block a user