From b90558430ec30fde624394b2703398731e704779 Mon Sep 17 00:00:00 2001 From: vladmandic Date: Wed, 25 Mar 2026 09:11:31 +0100 Subject: [PATCH] fix grid Signed-off-by: vladmandic --- modules/image/grid.py | 10 +--------- scripts/xyz_grid_on.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/image/grid.py b/modules/image/grid.py index 0c8745dbd..bfdb7c6cf 100644 --- a/modules/image/grid.py +++ b/modules/image/grid.py @@ -1,6 +1,5 @@ import math from collections import namedtuple -from typing import TYPE_CHECKING import numpy as np from PIL import Image, ImageFont, ImageDraw from modules import shared, script_callbacks @@ -35,16 +34,12 @@ def get_grid_size(imgs, batch_size=1, rows: int | None = None, cols: int | None if rows is None and cols is None: if shared.opts.n_rows > 0: rows = shared.opts.n_rows - if TYPE_CHECKING: - assert isinstance(rows, int) cols = math.ceil(len(imgs) / rows) elif shared.opts.n_rows == 0: rows = batch_size cols = math.ceil(len(imgs) / rows) elif shared.opts.n_cols > 0: cols = shared.opts.n_cols - if TYPE_CHECKING: - assert isinstance(cols, int) rows = math.ceil(len(imgs) / cols) elif shared.opts.n_cols == 0: cols = batch_size @@ -59,14 +54,11 @@ def get_grid_size(imgs, batch_size=1, rows: int | None = None, cols: int | None elif rows is None and cols is not None: rows = math.ceil(len(imgs) / cols) else: - if TYPE_CHECKING: - assert isinstance(rows, int) - assert isinstance(cols, int) pass return rows, cols -def image_grid(imgs, batch_size=1, rows=1, cols=1): +def image_grid(imgs, batch_size=1, rows: int | None = None, cols: int | None = None): rows, cols = get_grid_size(imgs, batch_size, rows=rows, cols=cols) params = script_callbacks.ImageGridLoopParams(imgs, cols, rows) script_callbacks.image_grid_callback(params) diff --git a/scripts/xyz_grid_on.py b/scripts/xyz_grid_on.py index 6a9af5b00..9439f7c00 100644 --- a/scripts/xyz_grid_on.py +++ b/scripts/xyz_grid_on.py @@ -428,8 +428,17 @@ class Script(scripts_manager.Script): info = processed.infotexts[g] prompt = processed.all_prompts[adj_g] seed = processed.all_seeds[adj_g] - debug(f'XYZ grid save grid: i={g+1}') - images.save_image(processed.images[g], p.outpath_grids, "grid", info=info, extension=shared.opts.grid_format, prompt=prompt, seed=seed, grid=True, p=processed) + debug(f"XYZ grid save grid: i={g + 1} images={processed.images[g]}") + images.save_image(processed.images[g], + path=p.outpath_grids, + basename="grid", + info=info, + extension=shared.opts.grid_format, + prompt=prompt, + seed=seed, + grid=True, + p=processed + ) if not include_subgrids and have_subgrids > 0: # done with sub-grids, drop all related information: for _sg in range(have_subgrids):