feat(*): fix calculations and bump

This commit is contained in:
meettya
2026-04-26 05:29:46 +03:00
parent 02cb40b55c
commit 0c99b53ef7
5 changed files with 39 additions and 17 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2025 Karpich Dmitry
Copyright (c) 2025-2026 Karpich Dmitry
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+3 -3
View File
@@ -2,17 +2,17 @@
## Image Fit Calculator
<img src="https://github.com/Meettya/ComfyUI-OneForOne-Demo/blob/b1f3ffa041d9b1f615553bb29ea2f74ded8b3b8b/examples/fit_calculator_node.jpg?raw=true" alt="Image Fit Calculator node" style="width: 50%; height: auto; display: block; margin-left: auto; margin-right: auto;">
<img src="https://github.com/Meettya/ComfyUI-OneForOne-Demo/blob/cfc49d3046acfc5e6d8c1e68a2dc3662d2f36475/examples/fit_calculator_node.jpg?raw=true" alt="Image Fit Calculator node" style="width: 50%; height: auto; display: block; margin-left: auto; margin-right: auto;">
<br/>
The ComfyUI custom node **Image Fit Calculator** is designed to automatically calculate new image parameters based on a given latent and original image. Specifically, this node can perform calculations for resizing an image and provide data for paddings to control its placement within the latent space. Additionally, it includes settings that allow users to specify horizontal or vertical offsets as well as reduce the size of the image. This node performs only computational tasks, while actual operations on the image may be carried out by external nodes if they have the capability to use input data to manipulate the result.
<img src="https://github.com/Meettya/ComfyUI-OneForOne-Demo/blob/b1f3ffa041d9b1f615553bb29ea2f74ded8b3b8b/examples/fit_calculator.jpg?raw=true" alt="Image Fit Calculator example" style="display: block; margin-left: auto; margin-right: auto;">
<img src="https://github.com/Meettya/ComfyUI-OneForOne-Demo/blob/cfc49d3046acfc5e6d8c1e68a2dc3662d2f36475/examples/fit_calculator.jpg?raw=true" alt="Image Fit Calculator example" style="display: block; margin-left: auto; margin-right: auto;">
In the provided workflow example, one can see how the ComfyUI node integrates with other components to streamline the process of image manipulation. This modular approach ensures flexibility and extensibility, enabling developers to easily incorporate new functionalities or optimize existing ones.
![Demo Animation](https://github.com/Meettya/ComfyUI-OneForOne-Demo/blob/0316b0b971aec47c097bf4389b16c213e6591038/examples/Fitcalcutator.gif?raw=true)
![Demo Animation](https://github.com/Meettya/ComfyUI-OneForOne-Demo/blob/cfc49d3046acfc5e6d8c1e68a2dc3662d2f36475/examples/Fitcalcutator.gif?raw=true)
If you encounter any bugs or have ideas for improving the ComfyUI node, feel free to create an issue or submit a pull request. Your contributions are highly appreciated and will help enhance this powerful tool for image processing automation.
+33 -11
View File
@@ -22,7 +22,7 @@ class OFOImageFit:
"required": {
"latent": ("LATENT",),
"image": ("IMAGE",),
"latent_scale": (SCALE_OPTIONS,),
"latent_scale": (SCALE_OPTIONS, {"default": SCALE_8X}),
},
"optional": {
"width_position": (
@@ -108,24 +108,46 @@ class OFOImageFit:
tuple: A tuple containing six integers representing the new width, height, top, right, bottom, and left padding values.
"""
scale_factor = SCALE_FACTOR_MAP[latent_scale]
latent_height, latent_width = get_latent_size(latent, scale_factor)
image_height, image_width = get_image_size(image)
# get minimum scale
# Compute base scaling (fit inside latent)
scale_w = latent_width / image_width
scale_h = latent_height / image_height
min_scale = min(scale_w, scale_h) * scale
# scale image
new_image_width = round(image_width * min_scale)
new_image_height = round(image_height * min_scale)
# Initial candidate dimensions (floored to avoid exceeding latent)
raw_width = int(image_width * min_scale)
raw_height = int(image_height * min_scale)
# calculate padding
padding_left = round((latent_width - new_image_width) * width_position)
padding_right = latent_width - new_image_width - padding_left
padding_bottom = round((latent_height - new_image_height) * height_position)
padding_top = latent_height - new_image_height - padding_bottom
# Ensure raw dimensions do not exceed latent bounds (safety)
raw_width = min(raw_width, latent_width)
raw_height = min(raw_height, latent_height)
# ----- Adjust to multiples of 8 -----
# We prefer rounding down to the nearest multiple of 8 (keep inside latent).
# But we also need to ensure we don't lose too much size.
# Let's find the largest multiple of 8 <= raw_width and <= raw_height.
target_width = (raw_width // 8) * 8
target_height = (raw_height // 8) * 8
# However, if the difference is too large (more than 7 pixels), we could try rounding up if still fits.
# But to be safe and keep exact fit, we just round down.
# If rounding down reduces size too much, the user can increase `scale`.
new_image_width = target_width
new_image_height = target_height
# ----- Recompute paddings based on final aligned sizes -----
# Horizontal padding
remaining_width = latent_width - new_image_width
padding_left = int(remaining_width * width_position)
padding_right = remaining_width - padding_left
# Vertical padding
remaining_height = latent_height - new_image_height
padding_top = int(remaining_height * height_position)
padding_bottom = remaining_height - padding_top
return (
new_image_width,
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "comfyui-oneforone"
description = "Node:Image Fit Calculator"
version = "1.0.1"
version = "2.0.1"
license = {file = "LICENSE"}
dependencies = ["numpy"]
File diff suppressed because one or more lines are too long