From 13487afa057c259f0ef26adff769b7524664af31 Mon Sep 17 00:00:00 2001 From: jerryipsum Date: Wed, 9 Apr 2025 19:44:42 +0100 Subject: [PATCH] Initial Commit --- .gitignore | 1 + LoadImageFromHttpURL.py | 34 ++++++++++++++++++++++++++++++++++ __init__.py | 9 +++++++++ 3 files changed, 44 insertions(+) create mode 100644 .gitignore create mode 100644 LoadImageFromHttpURL.py create mode 100644 __init__.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/LoadImageFromHttpURL.py b/LoadImageFromHttpURL.py new file mode 100644 index 0000000..c3269e6 --- /dev/null +++ b/LoadImageFromHttpURL.py @@ -0,0 +1,34 @@ +import requests +from PIL import Image +import io +import numpy as np +import torch + +class LoadImageFromHttpURL: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "image_url": ("STRING", { + "default": "https://placehold.co/600x400/EEE/31343C" + }), + } + } + + RETURN_TYPES = ("IMAGE",) + FUNCTION = "load_image" + CATEGORY = "jerrywap/loaders" + + def load_image(self, image_url: str): + try: + response = requests.get(image_url) + response.raise_for_status() + image = Image.open(io.BytesIO(response.content)).convert("RGB") + + image_np = np.array(image).astype(np.float32) / 255.0 + image_tensor = torch.from_numpy(image_np).unsqueeze(0) + + return (image_tensor,) + except Exception as e: + print(f"Failed to load image from URL: {e}") + return (torch.zeros(1, 512, 512, 3),) # fallback black image diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..80a7544 --- /dev/null +++ b/__init__.py @@ -0,0 +1,9 @@ +from .LoadImageFromHttpURL import LoadImageFromHttpURL + +NODE_CLASS_MAPPINGS = { + "LoadImageFromHttpURL": LoadImageFromHttpURL, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "LoadImageFromHttpURL": "Load Image from HTTP URL", +}