From 693326cbad6cbe37598adb263a7ea32e7897915a Mon Sep 17 00:00:00 2001 From: AbyssYuan0 Date: Wed, 18 Oct 2023 20:17:48 +0800 Subject: [PATCH] first commit --- README.md | 3 + __init__.py | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 README.md create mode 100644 __init__.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..8bc434e --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +个人使用小工具 +1.图片覆盖 +2.int转string,float转string,float转int四舍五入 \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..d6c62e1 --- /dev/null +++ b/__init__.py @@ -0,0 +1,172 @@ + +from PIL import Image +import numpy as np +import torch +class ImageOverlap: + + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + + return { + "required": { + "base_image": ("IMAGE",), + "additional_image": ("IMAGE",), + "x": ("INT", { + "default": 0, + "min": 0, + "max": 4096, + "step": 1, + "display": "number" + }), + "y": ("INT", { + "default": 0, + "min": 0, + "max": 4096, + "step": 1, + "display": "number" + }), + }, + } + + RETURN_TYPES = ("IMAGE",) + # RETURN_NAMES = ("image_output_name",) + + FUNCTION = "overlap" + + # OUTPUT_NODE = False + + CATEGORY = "badger" + + def tensorToImg(self, imageTensor): + imaget = imageTensor[0] + i = 255. * imaget.cpu().numpy() + img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8)) + return img + + def imgToTensor(self,img): + image = np.array(img).astype(np.float32) / 255.0 + imaget = torch.from_numpy(image)[None,] + return imaget + + def overlap(self, base_image, additional_image, x, y): + b_image = self.tensorToImg(base_image) + a_image = self.tensorToImg(additional_image) + + b_image.paste(a_image, (x, y)) + o_image = self.imgToTensor(b_image) + return (o_image,) + + +class FloatToInt: + + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + + return { + "required": { + "float": ("FLOAT", { + "default": 1.0, + "min": 0.0, + "max": 4096.0, + "step": 0.01, + "round": 0.01, + "display": "number"}) + }, + } + + RETURN_TYPES = ("INT",) + # RETURN_NAMES = ("image_output_name",) + + FUNCTION = "floatToInt" + + # OUTPUT_NODE = False + + CATEGORY = "badger" + + def floatToInt(self, float): + return (round(float),) + + +class IntToString: + + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + + return { + "required": { + "int": ("INT", { + "default": 0, + "min": 0, + "max": 4096, + "step": 1, + "display": "number" + }) + }, + } + + RETURN_TYPES = ("STRING",) + # RETURN_NAMES = ("image_output_name",) + + FUNCTION = "intToString" + + # OUTPUT_NODE = False + + CATEGORY = "badger" + + def intToString(self, int): + return (str(int),) + +class FloatToString: + + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + + return { + "required": { + "float": ("FLOAT", { + "default": 1.0, + "min": 0.0, + "max": 10.0, + "step": 0.00001, + "round": False, + "display": "number"}) + + }, + } + + RETURN_TYPES = ("STRING",) + # RETURN_NAMES = ("image_output_name",) + + FUNCTION = "floatToString" + + # OUTPUT_NODE = False + + CATEGORY = "badger" + + def floatToString(self, float): + return (str(float),) + + +NODE_CLASS_MAPPINGS = { + "ImageOverlap-badger": ImageOverlap, + "FloatToInt-badger": FloatToInt, + "IntToString-badger": IntToString, + "FloatToString-badger": FloatToString + +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "ImageOverlap": "Example test" +}