996 lines
29 KiB
Python
996 lines
29 KiB
Python
from PIL import ImageDraw, Image
|
|
|
|
|
|
class ImageDrawArc:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"width": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"height": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"size": ("INT", {
|
|
"default": 1,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"start_x": ("FLOAT", {
|
|
"default": 0.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"start_y": ("FLOAT", {
|
|
"default": 0.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_x": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_y": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"start": ("INT", {
|
|
"default": 0,
|
|
"max": 360,
|
|
"step": 1
|
|
}),
|
|
"end": ("INT", {
|
|
"default": 180,
|
|
"max": 360,
|
|
"step": 1
|
|
}),
|
|
"red": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"green": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"blue": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"SSAA": ("INT", {
|
|
"default": 8,
|
|
"min": 1,
|
|
"max": 16,
|
|
"step": 1
|
|
}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
FUNCTION = "image_draw_arc"
|
|
CATEGORY = "image/draw"
|
|
|
|
# noinspection PyPep8Naming, PyUnresolvedReferences
|
|
def image_draw_arc(self, width, height, size, start_x, start_y, end_x, end_y, start, end, red, green, blue, alpha, SSAA):
|
|
canvas = Image.new("RGBA", (width * SSAA, height * SSAA), (0, 0, 0, 0))
|
|
|
|
draw = ImageDraw.Draw(canvas)
|
|
draw.arc(
|
|
[
|
|
(width * start_x * SSAA, height * start_y * SSAA),
|
|
(width * end_x * SSAA, height * end_y * SSAA)
|
|
],
|
|
start, end, (red, green, blue, int(alpha * 255)), size * SSAA
|
|
)
|
|
|
|
canvas = canvas.resize((width, height), Image.ANTIALIAS)
|
|
|
|
return (canvas.image_to_tensor().unsqueeze(0),)
|
|
|
|
|
|
class ImageDrawChord:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"width": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"height": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"size": ("INT", {
|
|
"default": 1,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"start_x": ("FLOAT", {
|
|
"default": 0.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"start_y": ("FLOAT", {
|
|
"default": 0.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_x": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_y": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"start": ("INT", {
|
|
"default": 0,
|
|
"max": 360,
|
|
"step": 1
|
|
}),
|
|
"end": ("INT", {
|
|
"default": 180,
|
|
"max": 360,
|
|
"step": 1
|
|
}),
|
|
"red": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"green": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"blue": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"SSAA": ("INT", {
|
|
"default": 8,
|
|
"min": 1,
|
|
"max": 16,
|
|
"step": 1
|
|
}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
FUNCTION = "image_draw_chord"
|
|
CATEGORY = "image/draw"
|
|
|
|
# noinspection PyPep8Naming, PyUnresolvedReferences
|
|
def image_draw_chord(self, width, height, size, start_x, start_y, end_x, end_y, start, end, red, green, blue, alpha, SSAA):
|
|
canvas = Image.new("RGBA", (width * SSAA, height * SSAA), (0, 0, 0, 0))
|
|
|
|
draw = ImageDraw.Draw(canvas)
|
|
draw.chord(
|
|
[
|
|
(width * start_x * SSAA, height * start_y * SSAA),
|
|
(width * end_x * SSAA, height * end_y * SSAA)
|
|
],
|
|
start, end, (red, green, blue, int(alpha * 255)), size * SSAA
|
|
)
|
|
|
|
canvas = canvas.resize((width, height), Image.ANTIALIAS)
|
|
|
|
return (canvas.image_to_tensor().unsqueeze(0),)
|
|
|
|
|
|
class ImageDrawEllipse:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"width": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"height": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"start_x": ("FLOAT", {
|
|
"default": 0.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"start_y": ("FLOAT", {
|
|
"default": 0.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_x": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_y": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"outline_size": ("INT", {
|
|
"default": 1,
|
|
"step": 1
|
|
}),
|
|
"outline_red": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_green": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_blue": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"fill_red": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_green": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_blue": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"SSAA": ("INT", {
|
|
"default": 8,
|
|
"min": 1,
|
|
"max": 16,
|
|
"step": 1
|
|
}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
FUNCTION = "image_draw_ellipse"
|
|
CATEGORY = "image/draw"
|
|
|
|
# noinspection PyPep8Naming, PyUnresolvedReferences
|
|
def image_draw_ellipse(
|
|
self,
|
|
width,
|
|
height,
|
|
start_x,
|
|
start_y,
|
|
end_x,
|
|
end_y,
|
|
outline_size,
|
|
outline_red,
|
|
outline_green,
|
|
outline_blue,
|
|
outline_alpha,
|
|
fill_red,
|
|
fill_green,
|
|
fill_blue,
|
|
fill_alpha,
|
|
SSAA
|
|
):
|
|
canvas = Image.new("RGBA", (width * SSAA, height * SSAA), (0, 0, 0, 0))
|
|
|
|
draw = ImageDraw.Draw(canvas)
|
|
draw.ellipse(
|
|
[
|
|
(width * start_x * SSAA, height * start_y * SSAA),
|
|
(width * end_x * SSAA, height * end_y * SSAA)
|
|
],
|
|
(fill_red, fill_green, fill_blue, int(fill_alpha * 255)),
|
|
(outline_red, outline_green, outline_blue, int(outline_alpha * 255)),
|
|
outline_size * SSAA
|
|
)
|
|
|
|
canvas = canvas.resize((width, height), Image.ANTIALIAS)
|
|
|
|
return (canvas.image_to_tensor().unsqueeze(0),)
|
|
|
|
|
|
class ImageDrawLine:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"width": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"height": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"size": ("INT", {
|
|
"default": 1,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"start_x": ("FLOAT", {
|
|
"default": 0.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"start_y": ("FLOAT", {
|
|
"default": 0.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_x": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_y": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"red": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"green": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"blue": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"SSAA": ("INT", {
|
|
"default": 8,
|
|
"min": 1,
|
|
"max": 16,
|
|
"step": 1
|
|
}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
FUNCTION = "image_draw_line"
|
|
CATEGORY = "image/draw"
|
|
|
|
# noinspection PyPep8Naming, PyUnresolvedReferences
|
|
def image_draw_line(self, width, height, size, start_x, start_y, end_x, end_y, red, green, blue, alpha, SSAA):
|
|
canvas = Image.new("RGBA", (width * SSAA, height * SSAA), (0, 0, 0, 0))
|
|
|
|
draw = ImageDraw.Draw(canvas)
|
|
draw.line(
|
|
[
|
|
(width * start_x * SSAA, height * start_y * SSAA),
|
|
(width * end_x * SSAA, height * end_y * SSAA)
|
|
],
|
|
(red, green, blue, int(alpha * 255)), size * SSAA
|
|
)
|
|
|
|
canvas = canvas.resize((width, height), Image.ANTIALIAS)
|
|
|
|
return (canvas.image_to_tensor().unsqueeze(0),)
|
|
|
|
|
|
class ImageDrawPieslice:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"width": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"height": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"start_x": ("FLOAT", {
|
|
"default": 0.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"start_y": ("FLOAT", {
|
|
"default": 0.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_x": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_y": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"start": ("INT", {
|
|
"default": 0,
|
|
"max": 360,
|
|
"step": 1
|
|
}),
|
|
"end": ("INT", {
|
|
"default": 240,
|
|
"max": 360,
|
|
"step": 1
|
|
}),
|
|
"outline_size": ("INT", {
|
|
"default": 1,
|
|
"step": 1
|
|
}),
|
|
"outline_red": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_green": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_blue": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"fill_red": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_green": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_blue": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"SSAA": ("INT", {
|
|
"default": 8,
|
|
"min": 1,
|
|
"max": 16,
|
|
"step": 1
|
|
}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
FUNCTION = "image_draw_pieslice"
|
|
CATEGORY = "image/draw"
|
|
|
|
# noinspection PyPep8Naming, PyUnresolvedReferences
|
|
def image_draw_pieslice(
|
|
self,
|
|
width,
|
|
height,
|
|
start_x,
|
|
start_y,
|
|
end_x,
|
|
end_y,
|
|
start,
|
|
end,
|
|
outline_size,
|
|
outline_red,
|
|
outline_green,
|
|
outline_blue,
|
|
outline_alpha,
|
|
fill_red,
|
|
fill_green,
|
|
fill_blue,
|
|
fill_alpha,
|
|
SSAA
|
|
):
|
|
canvas = Image.new("RGBA", (width * SSAA, height * SSAA), (0, 0, 0, 0))
|
|
|
|
draw = ImageDraw.Draw(canvas)
|
|
draw.pieslice(
|
|
(
|
|
(width * start_x * SSAA, height * start_y * SSAA),
|
|
(width * end_x * SSAA, height * end_y * SSAA)
|
|
),
|
|
start, end,
|
|
(fill_red, fill_green, fill_blue, int(fill_alpha * 255)),
|
|
(outline_red, outline_green, outline_blue, int(outline_alpha * 255)),
|
|
outline_size * SSAA
|
|
)
|
|
|
|
canvas = canvas.resize((width, height), Image.ANTIALIAS)
|
|
|
|
return (canvas.image_to_tensor().unsqueeze(0),)
|
|
|
|
|
|
class ImageDrawPolygon:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"size": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"sides": ("INT", {
|
|
"default": 5,
|
|
"min": 3,
|
|
"step": 1
|
|
}),
|
|
"rotation": ("INT", {
|
|
"default": 0,
|
|
"max": 360,
|
|
"step": 1
|
|
}),
|
|
"outline_size": ("INT", {
|
|
"default": 1,
|
|
"step": 1
|
|
}),
|
|
"outline_red": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_green": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_blue": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"fill_red": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_green": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_blue": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"SSAA": ("INT", {
|
|
"default": 8,
|
|
"min": 1,
|
|
"max": 16,
|
|
"step": 1
|
|
}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
FUNCTION = "image_draw_polygon"
|
|
CATEGORY = "image/draw"
|
|
|
|
# noinspection PyPep8Naming, PyUnresolvedReferences
|
|
def image_draw_polygon(
|
|
self,
|
|
size,
|
|
sides,
|
|
rotation,
|
|
outline_size,
|
|
outline_red,
|
|
outline_green,
|
|
outline_blue,
|
|
outline_alpha,
|
|
fill_red,
|
|
fill_green,
|
|
fill_blue,
|
|
fill_alpha,
|
|
SSAA
|
|
):
|
|
canvas = Image.new("RGBA", (size * SSAA, size * SSAA), (0, 0, 0, 0))
|
|
|
|
draw = ImageDraw.Draw(canvas)
|
|
draw.regular_polygon(
|
|
(size * SSAA / 2, size * SSAA / 2, size * SSAA / 2),
|
|
sides, rotation,
|
|
(fill_red, fill_green, fill_blue, int(fill_alpha * 255)),
|
|
(outline_red, outline_green, outline_blue, int(outline_alpha * 255)),
|
|
# TODO: Uncomment after the release of PIL 9.6.0
|
|
# outline_size * SSAA
|
|
)
|
|
|
|
canvas = canvas.resize((size, size), Image.ANTIALIAS)
|
|
|
|
return (canvas.image_to_tensor().unsqueeze(0),)
|
|
|
|
|
|
class ImageDrawRectangle:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"width": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"height": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"start_x": ("FLOAT", {
|
|
"default": 0.1,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"start_y": ("FLOAT", {
|
|
"default": 0.2,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_x": ("FLOAT", {
|
|
"default": 0.9,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_y": ("FLOAT", {
|
|
"default": 0.8,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"outline_size": ("INT", {
|
|
"default": 1,
|
|
"step": 1
|
|
}),
|
|
"outline_red": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_green": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_blue": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"fill_red": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_green": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_blue": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"SSAA": ("INT", {
|
|
"default": 8,
|
|
"min": 1,
|
|
"max": 16,
|
|
"step": 1
|
|
}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
FUNCTION = "image_draw_rectangle"
|
|
CATEGORY = "image/draw"
|
|
|
|
# noinspection PyPep8Naming, PyUnresolvedReferences
|
|
def image_draw_rectangle(
|
|
self,
|
|
width,
|
|
height,
|
|
start_x,
|
|
start_y,
|
|
end_x,
|
|
end_y,
|
|
outline_size,
|
|
outline_red,
|
|
outline_green,
|
|
outline_blue,
|
|
outline_alpha,
|
|
fill_red,
|
|
fill_green,
|
|
fill_blue,
|
|
fill_alpha,
|
|
SSAA
|
|
):
|
|
canvas = Image.new("RGBA", (width * SSAA, height * SSAA), (0, 0, 0, 0))
|
|
|
|
draw = ImageDraw.Draw(canvas)
|
|
draw.rectangle(
|
|
(
|
|
(width * start_x * SSAA, height * start_y * SSAA),
|
|
(width * end_x * SSAA, height * end_y * SSAA)
|
|
),
|
|
(fill_red, fill_green, fill_blue, int(fill_alpha * 255)),
|
|
(outline_red, outline_green, outline_blue, int(outline_alpha * 255)),
|
|
outline_size * SSAA
|
|
)
|
|
|
|
canvas = canvas.resize((width, height), Image.ANTIALIAS)
|
|
|
|
return (canvas.image_to_tensor().unsqueeze(0),)
|
|
|
|
|
|
class ImageDrawRectangleRounded:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"width": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"height": ("INT", {
|
|
"default": 256,
|
|
"min": 1,
|
|
"step": 1
|
|
}),
|
|
"start_x": ("FLOAT", {
|
|
"default": 0.1,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"start_y": ("FLOAT", {
|
|
"default": 0.2,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_x": ("FLOAT", {
|
|
"default": 0.9,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"end_y": ("FLOAT", {
|
|
"default": 0.8,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"radius": ("INT", {
|
|
"default": 180,
|
|
"max": 360,
|
|
"step": 1
|
|
}),
|
|
"outline_size": ("INT", {
|
|
"default": 1,
|
|
"step": 1
|
|
}),
|
|
"outline_red": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_green": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_blue": ("INT", {
|
|
"default": 0,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"outline_alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"fill_red": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_green": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_blue": ("INT", {
|
|
"default": 255,
|
|
"max": 255,
|
|
"step": 1
|
|
}),
|
|
"fill_alpha": ("FLOAT", {
|
|
"default": 1.0,
|
|
"max": 1.0,
|
|
"step": 0.01
|
|
}),
|
|
"top_left_corner": (["true", "false"],),
|
|
"top_right_corner": (["true", "false"],),
|
|
"bottom_right_corner": (["true", "false"],),
|
|
"bottom_left_corner": (["true", "false"],),
|
|
"SSAA": ("INT", {
|
|
"default": 8,
|
|
"min": 1,
|
|
"max": 16,
|
|
"step": 1
|
|
}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
FUNCTION = "image_draw_rounded"
|
|
CATEGORY = "image/draw"
|
|
|
|
# noinspection PyPep8Naming, PyUnresolvedReferences, PyArgumentList
|
|
def image_draw_rounded(
|
|
self,
|
|
width,
|
|
height,
|
|
start_x,
|
|
start_y,
|
|
end_x,
|
|
end_y,
|
|
radius,
|
|
outline_size,
|
|
outline_red,
|
|
outline_green,
|
|
outline_blue,
|
|
outline_alpha,
|
|
fill_red,
|
|
fill_green,
|
|
fill_blue,
|
|
fill_alpha,
|
|
top_left_corner,
|
|
top_right_corner,
|
|
bottom_right_corner,
|
|
bottom_left_corner,
|
|
SSAA
|
|
):
|
|
canvas = Image.new("RGBA", (width * SSAA, height * SSAA), (0, 0, 0, 0))
|
|
|
|
draw = ImageDraw.Draw(canvas)
|
|
draw.rounded_rectangle(
|
|
(
|
|
(width * start_x * SSAA, height * start_y * SSAA),
|
|
(width * end_x * SSAA, height * end_y * SSAA)
|
|
),
|
|
radius,
|
|
(fill_red, fill_green, fill_blue, int(fill_alpha * 255)),
|
|
(outline_red, outline_green, outline_blue, int(outline_alpha * 255)),
|
|
outline_size * SSAA,
|
|
corners=(
|
|
True if top_left_corner == "true" else False,
|
|
True if top_right_corner == "true" else False,
|
|
True if bottom_right_corner == "true" else False,
|
|
True if bottom_left_corner == "true" else False
|
|
)
|
|
)
|
|
|
|
canvas = canvas.resize((width, height), Image.ANTIALIAS)
|
|
|
|
return (canvas.image_to_tensor().unsqueeze(0),)
|
|
|
|
|
|
NODE_CLASS_MAPPINGS = {
|
|
"ImageDrawArc": ImageDrawArc,
|
|
"ImageDrawChord": ImageDrawChord,
|
|
"ImageDrawEllipse": ImageDrawEllipse,
|
|
"ImageDrawLine": ImageDrawLine,
|
|
"ImageDrawPieslice": ImageDrawPieslice,
|
|
"ImageDrawPolygon": ImageDrawPolygon,
|
|
"ImageDrawRectangle": ImageDrawRectangle,
|
|
"ImageDrawRectangleRounded": ImageDrawRectangleRounded
|
|
}
|