|
1 | | -from calendar import c |
2 | | -from email.mime import image |
3 | 1 | import os |
4 | 2 | import io |
5 | | -from turtle import width |
6 | 3 | import requests |
7 | 4 | import json |
8 | 5 | import numpy as np |
9 | 6 | import cv2 |
10 | 7 | from io import BytesIO |
11 | 8 | from PIL import Image, ImageOps, ImageSequence, ImageFile, ImageDraw |
12 | 9 | from PIL.PngImagePlugin import PngInfo |
13 | | -from sympy import prime |
14 | 10 |
|
15 | 11 | import folder_paths |
16 | 12 | import comfy.utils |
@@ -237,6 +233,7 @@ def node_function(self, image, resize_to, side, interpolation, divisible_by_2): |
237 | 233 | elif side == "longest": |
238 | 234 | side = longer_side |
239 | 235 |
|
| 236 | + resize_to = float(resize_to) |
240 | 237 | if side == "width": |
241 | 238 | width = resize_to |
242 | 239 | height = image_height * (resize_to / image_width) |
@@ -542,6 +539,47 @@ def node_function(self, image, alpha_threshold, r, g, b): |
542 | 539 | return (tensor_filled,) |
543 | 540 |
|
544 | 541 |
|
| 542 | +class FillColorNode: |
| 543 | + def __init__(self): |
| 544 | + pass |
| 545 | + |
| 546 | + @classmethod |
| 547 | + def INPUT_TYPES(cls): |
| 548 | + return { |
| 549 | + "required": { |
| 550 | + "image": (IO.IMAGE, {"default": "", "forceInput": True}), |
| 551 | + "color": (IO.COLOR,), |
| 552 | + } |
| 553 | + } |
| 554 | + |
| 555 | + RETURN_TYPES = (IO.IMAGE,) |
| 556 | + RETURN_NAMES = ("image",) |
| 557 | + FUNCTION = "node_function" |
| 558 | + CATEGORY = "Fair/image" |
| 559 | + |
| 560 | + def fill_color(self, image, color): |
| 561 | + # change white to fill color |
| 562 | + pil = tensor_to_pil(image) |
| 563 | + |
| 564 | + pixels = pil.getdata() |
| 565 | + |
| 566 | + new_pixels = [] |
| 567 | + for pixel in pixels: |
| 568 | + r, g, b = pixel |
| 569 | + l = int(0.299 * r + 0.587 * g + 0.114 * b) |
| 570 | + # color lerp |
| 571 | + new_pixels.append((int(r + (color[0] - r) * (1 - l / 255.0)), int(g + (color[1] - g) * (1 - l / 255.0)), int(b + (color[2] - b) * (1 - l / 255.0)))) |
| 572 | + |
| 573 | + new_pil = Image.new("RGB", pil.size) |
| 574 | + new_pil.putdata(new_pixels) |
| 575 | + image_tensor = pil_to_tensor(new_pil) |
| 576 | + return image_tensor |
| 577 | + |
| 578 | + def node_function(self, image, color): |
| 579 | + tensor_filled = self.fill_color(image, color) |
| 580 | + return (tensor_filled,) |
| 581 | + |
| 582 | + |
545 | 583 | def pil_to_base64(pli_image, pnginfo=None, header=False): |
546 | 584 | # 创建一个BytesIO对象,用于临时存储图像数据 |
547 | 585 | image_data = io.BytesIO() |
@@ -829,7 +867,7 @@ def INPUT_TYPES(cls): |
829 | 867 | return { |
830 | 868 | "required": { |
831 | 869 | "images": (IO.IMAGE, {"defaultInput": True}), |
832 | | - "direction": (["up_to_down", "down_to_up", "left_to_right", "right_to_left"], {"default": "up_to_down"}), |
| 870 | + "direction": ("ModulationDirection", {"default": "up_to_down"}), |
833 | 871 | "speed": (IO.FLOAT, {"default": 0.01, "step": 0.01}), |
834 | 872 | } |
835 | 873 | } |
@@ -862,3 +900,24 @@ def node_function(self, images, direction, speed): |
862 | 900 |
|
863 | 901 | out_images = torch.stack(out_images, dim=0) |
864 | 902 | return (out_images,) |
| 903 | + |
| 904 | + |
| 905 | +class ModulationDirectionNode: |
| 906 | + def __init__(self): |
| 907 | + pass |
| 908 | + |
| 909 | + @classmethod |
| 910 | + def INPUT_TYPES(cls): |
| 911 | + return { |
| 912 | + "required": { |
| 913 | + "direction": (["up_to_down", "down_to_up", "left_to_right", "right_to_left"], {"default": "up_to_down"}), |
| 914 | + } |
| 915 | + } |
| 916 | + |
| 917 | + FUNCTION = "node_function" |
| 918 | + CATEGORY = "Fair/image" |
| 919 | + RETURN_TYPES = ("ModulationDirection",) |
| 920 | + RETURN_NAMES = ("direction",) |
| 921 | + |
| 922 | + def node_function(self, direction): |
| 923 | + return (direction,) |
0 commit comments