Skip to content

Commit 7dbd5f1

Browse files
feat(nodes): add BoundingBoxField.tuple() to get bbox as PIL tuple
1 parent 1ad65ff commit 7dbd5f1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

invokeai/app/invocations/fields.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ def check_coords(self):
300300
raise ValueError(f"y_min ({self.y_min}) is greater than y_max ({self.y_max}).")
301301
return self
302302

303+
def tuple(self) -> Tuple[int, int, int, int]:
304+
"""
305+
Returns the bounding box as a tuple suitable for use with PIL's `Image.crop()` method.
306+
This method returns a tuple of the form (left, upper, right, lower) == (x_min, y_min, x_max, y_max).
307+
"""
308+
return (self.x_min, self.y_min, self.x_max, self.y_max)
309+
303310

304311
class MetadataField(RootModel[dict[str, Any]]):
305312
"""

0 commit comments

Comments
 (0)