commit 6ebe3d62062caae0cb689da2ac2ad9b80287709a Author: Yiheng Date: Tue May 21 02:02:21 2024 +0800 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..dc61ced --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# Introduction +GetFileNameFromURL is a ComfyUI custom node that extracts the filename from a URL. It can handle various URLs and is capable of handling redirects. +image + +# Features +Extracts filename from a URL +Handles 303 redirects +# Usage +In your terminal, navigate to the custom_nodes directory of your ComfyUI installation. +Clone this repository using the git clone command: +```bash +git clone https://github.com/your-username/your-repository.git +``` +Restart ComfyUI. +In ComfyUI, locate the "Get FileName From URL" node. +Input the desired URL into the node's url field. +Run the node, and it will output both the extracted filename and the original URL. +# Inputs +url (STRING): The URL from which to extract the filename. +# Outputs +filename (STRING): The extracted filename. +url (STRING): The input URL. +# Example +## Input: +* https://example.com/path/to/file.jpg + +## Output: + +* filename: file.jpg +* url: https://example.com/path/to/file.jpg +# Dependencies +requests +cgi diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..f321979 --- /dev/null +++ b/__init__.py @@ -0,0 +1,3 @@ +from .add_border_to_image import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS + +__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS'] \ No newline at end of file diff --git a/add_border_to_image.py b/add_border_to_image.py new file mode 100644 index 0000000..9197684 --- /dev/null +++ b/add_border_to_image.py @@ -0,0 +1,60 @@ +import numpy as np +from PIL import Image + + +class ChangeImageBorder: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "image": ("IMAGE", ), + "value": ("INT", {"default": 0}), + "border_size": ("INT", {"default": 2}), + }, + } + + RETURN_TYPES = ("IMAGE",) + RETURN_NAMES = ("image",) + FUNCTION = "change_border_to" + CATEGORY = "Tools" + + def change_border_to(image_path, value, border_size=2): + # Open the image file + with Image.open(image_path) as img: + # Convert to RGBA if it's not already in this mode + img = img.convert("RGBA") + + # Get the image data + data = np.array(img) + + # Change the top and bottom border pixels + data[:border_size, :] = [value, value, value, 255] # top + data[-border_size:, :] = [value, value, value, 255] # bottom + + # Change the left and right border pixels + data[:, :border_size] = [value, value, value, 255] # left + data[:, -border_size:] = [value, value, value, 255] # right + + # Create a new image from the modified data + new_img = Image.fromarray(data, mode='RGBA') + + # Return the new image + return new_img + +# Set the web directory, any .js file in that directory will be loaded by the frontend as a frontend extension +# WEB_DIRECTORY = "./somejs" + + +# A dictionary that contains all nodes you want to export with their names +# NOTE: names should be globally unique +NODE_CLASS_MAPPINGS = { + "ChangeImageBorder": ChangeImageBorder +} + +# A dictionary that contains the friendly/humanly readable titles for the nodes +NODE_DISPLAY_NAME_MAPPINGS = { + "ChangeImageBorder": "Change Image Border" +}