Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

fix: Bug when setting transparency in color picker (#14764)

Alexis Rolland7f287b705e3d
diff --git a/comfy_extras/nodes_color.py b/comfy_extras/nodes_color.py
index f58e51bff..6d10b26f4 100644
--- a/comfy_extras/nodes_color.py
+++ b/comfy_extras/nodes_color.py
@@ -16,23 +16,30 @@ class ColorToRGBInt(io.ComfyNode):
],
outputs=[
io.Int.Output(display_name="rgb_int"),
- io.Color.Output(display_name="hex")
+ io.Color.Output(display_name="hex"),
+ io.Float.Output(display_name="alpha"),
],
)
@classmethod
def execute(cls, color: str) -> io.NodeOutput:
- # expect format #RRGGBB
- if len(color) != 7 or color[0] != "#":
- raise ValueError("Color must be in format #RRGGBB")
+ # expect format #RRGGBB or #RRGGBBAA
+ if len(color) not in (7, 9) or color[0] != "#":
+ raise ValueError("Color must be in format #RRGGBB or #RRGGBBAA")
try:
int(color[1:], 16)
except ValueError:
- raise ValueError("Color must be in format #RRGGBB") from None
+ raise ValueError("Color must be in format #RRGGBB or #RRGGBBAA") from None
+
+ alpha = 1.0
+ if len(color) == 9:
+ alpha = int(color[7:9], 16) / 255.0
+ color = color[:7]
+
r, g, b = hex_to_rgb(color)
rgb_int = r * 256 * 256 + g * 256 + b
- return io.NodeOutput(rgb_int, color)
+ return io.NodeOutput(rgb_int, color, alpha)
class ColorExtension(ComfyExtension):