From 504fd3a445a7c62970d5abd1a6cfbeb7e7dc26bc Mon Sep 17 00:00:00 2001 From: AbyssYuan0 Date: Mon, 15 Jan 2024 12:49:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=8C=87=E5=AE=9A=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E6=89=A9=E5=B1=95=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index a59acf8..4800d66 100644 --- a/__init__.py +++ b/__init__.py @@ -786,7 +786,6 @@ class TrimTransparentEdges: FUNCTION = "trim_transparent_edges" def trim_transparent_edges(self, image): - img = tensorToImg(image) img = img.convert("RGBA") @@ -815,6 +814,73 @@ class TrimTransparentEdges: return (cropped_img,) +class ExpandImageWithColor: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "image": ("IMAGE",), + "top": ("INT", { + "default": 0, + "min": 0, + "max": 1024, + "step": 1, + "display": "number" + }), + "bottom": ("INT", { + "default": 0, + "min": 0, + "max": 1024, + "step": 1, + "display": "number" + }), + "left": ("INT", { + "default": 0, + "min": 0, + "max": 1024, + "step": 1, + "display": "number" + }), + "right": ("INT", { + "default": 0, + "min": 0, + "max": 1024, + "step": 1, + "display": "number" + }), + }, + "optional": { + "color": ("STRING", {"default": None}), + } + } + + CATEGORY = "badger" + + RETURN_TYPES = ("IMAGE",) + FUNCTION = "expand_image_with_color" + + def expand_image_with_color(self,image, top, bottom, left, right, color=None): + img = tensorToImg(image) + + # Determine the new size of the image + new_width = img.width + left + right + new_height = img.height + top + bottom + + # Create a new image with the new size and the given background color + if color: + new_img = Image.new("RGBA", (new_width, new_height), color) + else: + # Use transparency if no color was provided + new_img = Image.new("RGBA", (new_width, new_height), (0, 0, 0, 0)) + + # Paste the original image onto the new image + new_img.paste(img, (left, top), img) + + result = imgToTensor(new_img) + + return (result,) + + NODE_CLASS_MAPPINGS = { "ImageOverlap-badger": ImageOverlap, "FloatToInt-badger": FloatToInt, @@ -834,7 +900,8 @@ NODE_CLASS_MAPPINGS = { "ApplyMaskToImage-badger": ApplyMaskToImage, "deleteDir-badger": deleteDir, "FindThickLinesFromCanny-badger": FindThickLinesFromCanny, - "TrimTransparentEdges-badger": TrimTransparentEdges + "TrimTransparentEdges-badger": TrimTransparentEdges, + "ExpandImageWithColor-badger": ExpandImageWithColor, } NODE_DISPLAY_NAME_MAPPINGS = {