Signed-off-by: vladmandic <mandic00@live.com>
pull/4708/head
vladmandic 2026-03-25 09:11:31 +01:00
parent 7a47b6bbdb
commit b90558430e
2 changed files with 12 additions and 11 deletions

View File

@ -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)

View File

@ -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):