Skip to content

Commit a5ab952

Browse files
committed
image
1 parent 4727382 commit a5ab952

File tree

4 files changed

+94
-6
lines changed

4 files changed

+94
-6
lines changed

__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from .nodes.image_utility import ImagesCatNode
3535
from .nodes.image_utility import ImagesInfoNode
3636
from .nodes.image_utility import ModulationNode
37+
from .nodes.image_utility import ModulationDirectionNode
3738

3839

3940
from .nodes.utility import PrintAnyNode
@@ -48,6 +49,7 @@
4849
from .nodes.logic import AddNode
4950
from .nodes.logic import SubtractNode
5051
from .nodes.logic import MultiplyNode
52+
from .nodes.logic import MultiplyIntNode
5153
from .nodes.logic import DivideNode
5254
from .nodes.logic import NumberNode
5355
from .nodes.logic import IfNode
@@ -90,6 +92,7 @@
9092
"AddNode": AddNode,
9193
"SubtractNode": SubtractNode,
9294
"MultiplyNode": MultiplyNode,
95+
"MultiplyIntNode": MultiplyIntNode,
9396
"DivideNode": DivideNode,
9497
"NumberNode": NumberNode,
9598
"IfNode": IfNode,
@@ -105,6 +108,7 @@
105108
"Base64ToImageNode": Base64ToImageNode,
106109
"ASCIICharNode": ASCIICharNode,
107110
"ModulationNode": ModulationNode,
111+
"ModulationDirectionNode": ModulationDirectionNode,
108112
}
109113

110114
NODE_DISPLAY_NAME_MAPPINGS = {
@@ -142,6 +146,7 @@
142146
"AddNode": "Add",
143147
"SubtractNode": "Subtract",
144148
"MultiplyNode": "Multiply",
149+
"MultiplyIntNode": "Multiply Int",
145150
"DivideNode": "Divide",
146151
"NumberNode": "Number",
147152
"IfNode": "If",
@@ -157,6 +162,7 @@
157162
"ImagesInfoNode": "Images Info",
158163
"ASCIICharNode": "ASCII Art Text",
159164
"ModulationNode": "Modulation",
165+
"ModulationDirectionNode": "Modulation Direction",
160166
}
161167

162168

nodes/image_utility.py

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
from calendar import c
2-
from email.mime import image
31
import os
42
import io
5-
from turtle import width
63
import requests
74
import json
85
import numpy as np
96
import cv2
107
from io import BytesIO
118
from PIL import Image, ImageOps, ImageSequence, ImageFile, ImageDraw
129
from PIL.PngImagePlugin import PngInfo
13-
from sympy import prime
1410

1511
import folder_paths
1612
import comfy.utils
@@ -237,6 +233,7 @@ def node_function(self, image, resize_to, side, interpolation, divisible_by_2):
237233
elif side == "longest":
238234
side = longer_side
239235

236+
resize_to = float(resize_to)
240237
if side == "width":
241238
width = resize_to
242239
height = image_height * (resize_to / image_width)
@@ -542,6 +539,47 @@ def node_function(self, image, alpha_threshold, r, g, b):
542539
return (tensor_filled,)
543540

544541

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+
545583
def pil_to_base64(pli_image, pnginfo=None, header=False):
546584
# 创建一个BytesIO对象,用于临时存储图像数据
547585
image_data = io.BytesIO()
@@ -829,7 +867,7 @@ def INPUT_TYPES(cls):
829867
return {
830868
"required": {
831869
"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"}),
833871
"speed": (IO.FLOAT, {"default": 0.01, "step": 0.01}),
834872
}
835873
}
@@ -862,3 +900,24 @@ def node_function(self, images, direction, speed):
862900

863901
out_images = torch.stack(out_images, dim=0)
864902
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,)

nodes/logic.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,29 @@ def node_function(self, a, b):
112112
return (out_value,)
113113

114114

115+
class MultiplyIntNode:
116+
def __init__(self):
117+
pass
118+
119+
@classmethod
120+
def INPUT_TYPES(cls):
121+
return {
122+
"required": {
123+
"a": (IO.INT,),
124+
"b": (IO.INT,),
125+
},
126+
}
127+
128+
FUNCTION = "node_function"
129+
CATEGORY = "Fair/logic"
130+
RETURN_TYPES = (IO.INT,)
131+
132+
def node_function(self, a, b):
133+
out_value = a * b
134+
out_value = int(out_value)
135+
return (out_value,)
136+
137+
115138
class DivideNode:
116139
def __init__(self):
117140
pass

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Python Script
6363
6464
Load LoRA Dual
6565
"""
66-
version = "1.0.75"
66+
version = "1.0.76"
6767
license = { file = "LICENSE" }
6868
dependencies = [
6969
"googletrans",

0 commit comments

Comments
 (0)