Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions modules/ImageText.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,18 @@ def INPUT_TYPES(cls):
"default": 0,
"step": 1
}),
"spacing": ("INT", {
"default": 4,
"step": 1
}),
},
}

RETURN_TYPES = ("IMAGE",)
FUNCTION = "node"
CATEGORY = "image/draw"

def node(self, text, font, align, size, red, green, blue, alpha, margin_x, margin_y):
def node(self, text, font, align, size, red, green, blue, alpha, margin_x, margin_y, spacing):
outline_size = 0
outline_red = 255
outline_green = 255
Expand All @@ -242,7 +246,8 @@ def node(self, text, font, align, size, red, green, blue, alpha, margin_x, margi
outline_blue,
alpha,
margin_x,
margin_y
margin_y,
spacing
)


Expand Down Expand Up @@ -309,6 +314,10 @@ def INPUT_TYPES(cls):
"default": 0,
"step": 1
}),
"spacing": ("INT", {
"default": 4,
"step": 1
}),
},
}

Expand All @@ -318,7 +327,7 @@ def INPUT_TYPES(cls):

def node(
self, text, font, align, size, red, green, blue, outline_size, outline_red, outline_green, outline_blue,
alpha, margin_x, margin_y
alpha, margin_x, margin_y, spacing
):
font_path = folder_paths.get_full_path("fonts", font)
font = ImageFont.truetype(font_path, size, encoding="unic")
Expand All @@ -328,7 +337,7 @@ def node(

canvas = Image.new("RGBA", (0, 0))
draw = ImageDraw.Draw(canvas)
text_size = draw.multiline_textbbox((0, 0), text, font)
text_size = draw.multiline_textbbox((0, 0), text, font, spacing=spacing)

canvas = Image.new("RGBA", (
text_size[2] + (margin_x + outline_size) * 2,
Expand All @@ -341,7 +350,7 @@ def node(
(margin_x + outline_size, margin_y + outline_size - top),
text=text, fill=(red, green, blue, int(alpha * 255)),
stroke_fill=(outline_red, outline_green, outline_blue, int(alpha * 255)),
stroke_width=outline_size, font=font, align=align
stroke_width=outline_size, font=font, align=align, spacing=spacing
)

return (canvas.image_to_tensor().unsqueeze(0),)
Expand Down