diff --git a/README.md b/README.md index cb2186c..75cee44 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 🔗 Comfyui : Bjornulf_custom_nodes v0.11 🔗 +# 🔗 Comfyui : Bjornulf_custom_nodes v0.12 🔗 # Dependencies @@ -20,6 +20,7 @@ - **v0.9**: Add a new node : Return one random line from input. - **v0.10**: Add a new node : Loop (All Lines from input) - Iterate over all lines from an input text. - **v0.11**: Add a new node : Text with random Seed - Generate a random seed, along with text. +- **v0.12**: Combine images : Add option to move vertically and horizontally. (from -50% to 150%) # 📝 Nodes descriptions @@ -172,8 +173,8 @@ But you can sometimes also want a black and white image... ![Combine Images](screenshots/combine_background_overlay.png) **Description:** -Combine two images into a single image : a background and one (or several) transparent overlay. (allow for video frames.) -Update 0.8 : Also have a option to put image top, bottom or center. +Combine two images into a single image : a background and one (or several) transparent overlay. (allow to have a video there, just send all the frames and recombine them after.) +Update 0.11 : Add option to move vertically and horizontally. (from -50% to 150%) ❗ Warning : For now, `background` is a static image. (I will allow video there later too.) ## 25 - 🟩➜▢ Green Screen to Transparency diff --git a/combine_background_overlay.py b/combine_background_overlay.py index f0bdd6c..0a8ca94 100644 --- a/combine_background_overlay.py +++ b/combine_background_overlay.py @@ -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 diff --git a/screenshots/combine_background_overlay.png b/screenshots/combine_background_overlay.png index bbc7c4f..c0cc922 100644 Binary files a/screenshots/combine_background_overlay.png and b/screenshots/combine_background_overlay.png differ