mirror of https://github.com/vladmandic/automatic
parent
7a47b6bbdb
commit
b90558430e
|
|
@ -1,6 +1,5 @@
|
||||||
import math
|
import math
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import Image, ImageFont, ImageDraw
|
from PIL import Image, ImageFont, ImageDraw
|
||||||
from modules import shared, script_callbacks
|
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 rows is None and cols is None:
|
||||||
if shared.opts.n_rows > 0:
|
if shared.opts.n_rows > 0:
|
||||||
rows = shared.opts.n_rows
|
rows = shared.opts.n_rows
|
||||||
if TYPE_CHECKING:
|
|
||||||
assert isinstance(rows, int)
|
|
||||||
cols = math.ceil(len(imgs) / rows)
|
cols = math.ceil(len(imgs) / rows)
|
||||||
elif shared.opts.n_rows == 0:
|
elif shared.opts.n_rows == 0:
|
||||||
rows = batch_size
|
rows = batch_size
|
||||||
cols = math.ceil(len(imgs) / rows)
|
cols = math.ceil(len(imgs) / rows)
|
||||||
elif shared.opts.n_cols > 0:
|
elif shared.opts.n_cols > 0:
|
||||||
cols = shared.opts.n_cols
|
cols = shared.opts.n_cols
|
||||||
if TYPE_CHECKING:
|
|
||||||
assert isinstance(cols, int)
|
|
||||||
rows = math.ceil(len(imgs) / cols)
|
rows = math.ceil(len(imgs) / cols)
|
||||||
elif shared.opts.n_cols == 0:
|
elif shared.opts.n_cols == 0:
|
||||||
cols = batch_size
|
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:
|
elif rows is None and cols is not None:
|
||||||
rows = math.ceil(len(imgs) / cols)
|
rows = math.ceil(len(imgs) / cols)
|
||||||
else:
|
else:
|
||||||
if TYPE_CHECKING:
|
|
||||||
assert isinstance(rows, int)
|
|
||||||
assert isinstance(cols, int)
|
|
||||||
pass
|
pass
|
||||||
return rows, cols
|
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)
|
rows, cols = get_grid_size(imgs, batch_size, rows=rows, cols=cols)
|
||||||
params = script_callbacks.ImageGridLoopParams(imgs, cols, rows)
|
params = script_callbacks.ImageGridLoopParams(imgs, cols, rows)
|
||||||
script_callbacks.image_grid_callback(params)
|
script_callbacks.image_grid_callback(params)
|
||||||
|
|
|
||||||
|
|
@ -428,8 +428,17 @@ class Script(scripts_manager.Script):
|
||||||
info = processed.infotexts[g]
|
info = processed.infotexts[g]
|
||||||
prompt = processed.all_prompts[adj_g]
|
prompt = processed.all_prompts[adj_g]
|
||||||
seed = processed.all_seeds[adj_g]
|
seed = processed.all_seeds[adj_g]
|
||||||
debug(f'XYZ grid save grid: i={g+1}')
|
debug(f"XYZ grid save grid: i={g + 1} images={processed.images[g]}")
|
||||||
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)
|
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:
|
if not include_subgrids and have_subgrids > 0: # done with sub-grids, drop all related information:
|
||||||
for _sg in range(have_subgrids):
|
for _sg in range(have_subgrids):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue