mirror of
https://github.com/justUmen/Bjornulf_custom_nodes.git
synced 2026-03-26 14:48:51 -03:00
v0.12
This commit is contained in:
@@ -9,7 +9,8 @@ class CombineBackgroundOverlay:
|
||||
"required": {
|
||||
"background": ("IMAGE",),
|
||||
"overlay_alpha": ("IMAGE",),
|
||||
"position": (["middle", "top", "bottom"],),
|
||||
"horizontal_position": ("FLOAT", {"default": 50, "min": -50, "max": 150, "step": 0.1}),
|
||||
"vertical_position": ("FLOAT", {"default": 50, "min": -50, "max": 150, "step": 0.1}),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -17,7 +18,7 @@ class CombineBackgroundOverlay:
|
||||
FUNCTION = "combine_background_overlay"
|
||||
CATEGORY = "Bjornulf"
|
||||
|
||||
def combine_background_overlay(self, background, overlay_alpha, position):
|
||||
def combine_background_overlay(self, background, overlay_alpha, horizontal_position, vertical_position):
|
||||
# Convert background from torch tensor to numpy array
|
||||
bg = background[0].numpy()
|
||||
bg = (bg * 255).astype(np.uint8)
|
||||
@@ -37,14 +38,11 @@ class CombineBackgroundOverlay:
|
||||
ov_img = Image.fromarray(ov, 'RGB')
|
||||
ov_img = ov_img.convert('RGBA')
|
||||
|
||||
# Calculate position based on user selection
|
||||
x = (bg_img.width - ov_img.width) // 2
|
||||
if position == "middle":
|
||||
y = (bg_img.height - ov_img.height) // 2
|
||||
elif position == "top":
|
||||
y = 0
|
||||
else: # bottom
|
||||
y = bg_img.height - ov_img.height
|
||||
# Calculate horizontal position
|
||||
x = int((horizontal_position / 100) * (bg_img.width - ov_img.width))
|
||||
|
||||
# Calculate vertical position
|
||||
y = int((vertical_position / 100) * (bg_img.height - ov_img.height))
|
||||
|
||||
# Create a new image for this overlay
|
||||
result = Image.new('RGBA', bg_img.size, (0, 0, 0, 0))
|
||||
@@ -52,7 +50,7 @@ class CombineBackgroundOverlay:
|
||||
# Paste the background
|
||||
result.paste(bg_img, (0, 0))
|
||||
|
||||
# Paste the overlay in the selected position
|
||||
# Paste the overlay in the calculated position
|
||||
result.paste(ov_img, (x, y), ov_img)
|
||||
|
||||
# Convert back to numpy array and then to torch tensor
|
||||
|
||||
Reference in New Issue
Block a user