Development Tips - Suzie1/ComfyUI_Guide_To_Making_Custom_Nodes GitHub Wiki
Here a few tips to help accelerate your node development
ChatGPT
GPT is amazing tool for helping write functions.
Here is an example prompt used in Tutorial #4:
write a python function to draw centered text on a colored background using the PIL library
use the following input parameters
image_width, image_height, text, font_size, font_color, background_color
Here is the GPT3.5 output:
from PIL import Image, ImageDraw, ImageFont
def draw_centered_text(image_width, image_height, text, font_size, font_color, background_color):
# Create a new image with the specified dimensions and background color
image = Image.new("RGB", (image_width, image_height), background_color)
draw = ImageDraw.Draw(image)
# Load a font (you can adjust the font path as needed)
font = ImageFont.load_default()
# Calculate the position to center the text
text_width, text_height = draw.textsize(text, font)
x = (image_width - text_width) // 2
y = (image_height - text_height) // 2
# Draw the text on the image
draw.text((x, y), text, font=font, fill=font_color)
# Save or display the image
image.save("centered_text_image.png")
image.show()
Prototyping
- A prototype node is a node that contains the class structure and INPUT_TYPES, and just enough code to produce a valid ouput
- It doesn't include library imports, the main function logic or any sub-functions
For example a prototype for the node in Tutorial #4 would look like this:
class HelloWorldProtoType:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"image_width": ("INT", {"default": 512, "min": 64, "max": 2048}),
"image_height": ("INT", {"default": 512, "min": 64, "max": 2048}),
"text": ("STRING", {"multiline": True, "default": "Hello World"}),
"font_size": ("INT", {"default": 50, "min": 1, "max": 1024}),
"font_color": (["white", "black", "red", "green", "blue", "yellow"],),
"background_color": (["white", "black", "red", "green", "blue", "yellow"],),
}
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "draw_overlay_text"
CATEGORY = "Tutorial Nodes"
def draw_overlay_text(self, image_width, image_height, text,
font_size, font_color, background_color):
return (image_out)
- The protype node will display in UI and can be connected to other nodes, but will not be fully functional
- It can be used for making mockups of nodes for discussion with collaborators before committing to a final design
- In this example it will be possible to connect the prototype node to a
Preview Image
node, but an error will be produced in the workflow is run
name 'image_out' is not defined