From 3aa78cec01292a086dddaa26a9905cbdb6c5ca46 Mon Sep 17 00:00:00 2001 From: SLAPaper Date: Thu, 6 Apr 2023 04:14:37 +0800 Subject: [PATCH] Feat: first implementation --- README.md | 22 ++++++++++++++++- __init__.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 __init__.py diff --git a/README.md b/README.md index 615aa6e..3724bf1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,22 @@ # ComfyUI-Image-Selector -Select one or some of images from a batch + +A custom node for (ComfyUI)[https://github.com/comfyanonymous/ComfyUI], which can select one or some of images from a batch. + +## Background + +ComfyUI dosn't handle batch generation seeds like A1111 WebUI do, so you can't simply increase the generation seed to get the desire image from a batch generation. + +So here is a simple node that can select some of the images from a batch and pipe through for further use, such as scaling up or "hires fix". + +Or you can use PreviewImage Node to go through all the images, and then rewire SaveImage with ImageSelector to save the one you want. + +## Usage + +Input: a list of selected indexes, start with 1 (not 0, sorry), seperated by comma. + +For example (no surronding quotes): + +1. "1": select the first image +2. "1,3,4,6,7": select the 1st, 3rd, 4th, 6th and 7th image + +All indexes that cannot convert to integer or out of bounds will be ignored. diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..9ba12e4 --- /dev/null +++ b/__init__.py @@ -0,0 +1,69 @@ +# Copyright 2023 SLAPaper +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import typing as tg + + +class ImageSelector: + """ + Select some of the images and pipe through + """ + + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + """ + Input: list of index of selected image, seperated by comma + Indexes start with 1 for simplicity + """ + return { + "required": { + "images": ("IMAGE", ), + "selected_images": ("STRING", { + "multiline": False, + "default": "1,2,3" + }), + }, + } + + RETURN_TYPES = ("IMAGE", ) + #RETURN_NAMES = ("image_output_name",) + + FUNCTION = "run" + + OUTPUT_NODE = False + + CATEGORY = "image" + + def run(self, images: tg.Sequence[tg.Any], selected_images: tg.Text): + res_images: tg.List[tg.Any] = [] + for s in selected_images.strip().split(','): + try: + x: int = int(s.strip()) - 1 + if x < len(images): + res_images.append(images[x]) + except: + pass + + if res_images: + return (res_images, ) + + return (images, ) + + +# A dictionary that contains all nodes you want to export with their names +# NOTE: names should be globally unique +NODE_CLASS_MAPPINGS = {"ImageSelector": ImageSelector}