multi size grid
This commit is contained in:
parent
d2097dbdd9
commit
abacb735f4
|
@ -54,11 +54,14 @@ def image_grid(imgs, batch_size=1, rows=None):
|
||||||
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)
|
||||||
|
|
||||||
w, h = imgs[0].size
|
w, h = map(max, zip(*(img.size for img in imgs)))
|
||||||
grid = Image.new('RGB', size=(params.cols * w, params.rows * h), color='black')
|
grid_background_color = ImageColor.getcolor(opts.grid_background_color, 'RGB')
|
||||||
|
grid = Image.new('RGB', size=(params.cols * w, params.rows * h), color=grid_background_color)
|
||||||
|
|
||||||
for i, img in enumerate(params.imgs):
|
for i, img in enumerate(params.imgs):
|
||||||
grid.paste(img, box=(i % params.cols * w, i // params.cols * h))
|
img_w, img_h = img.size
|
||||||
|
w_offset, h_offset = 0 if img_w == w else (w - img_w) // 2, 0 if img_h == h else (h - img_h) // 2
|
||||||
|
grid.paste(img, box=(i % params.cols * w + w_offset, i // params.cols * h + h_offset))
|
||||||
|
|
||||||
return grid
|
return grid
|
||||||
|
|
||||||
|
|
|
@ -375,16 +375,18 @@ def draw_xyz_grid(p, xs, ys, zs, x_labels, y_labels, z_labels, cell, draw_legend
|
||||||
end_index = start_index + len(xs) * len(ys)
|
end_index = start_index + len(xs) * len(ys)
|
||||||
grid = images.image_grid(processed_result.images[start_index:end_index], rows=len(ys))
|
grid = images.image_grid(processed_result.images[start_index:end_index], rows=len(ys))
|
||||||
if draw_legend:
|
if draw_legend:
|
||||||
grid = images.draw_grid_annotations(grid, processed_result.images[start_index].size[0], processed_result.images[start_index].size[1], hor_texts, ver_texts, margin_size)
|
grid_max_w, grid_max_h = map(max, zip(*(img.size for img in processed_result.images[start_index:end_index])))
|
||||||
|
grid = images.draw_grid_annotations(grid, grid_max_w, grid_max_h, hor_texts, ver_texts, margin_size)
|
||||||
processed_result.images.insert(i, grid)
|
processed_result.images.insert(i, grid)
|
||||||
processed_result.all_prompts.insert(i, processed_result.all_prompts[start_index])
|
processed_result.all_prompts.insert(i, processed_result.all_prompts[start_index])
|
||||||
processed_result.all_seeds.insert(i, processed_result.all_seeds[start_index])
|
processed_result.all_seeds.insert(i, processed_result.all_seeds[start_index])
|
||||||
processed_result.infotexts.insert(i, processed_result.infotexts[start_index])
|
processed_result.infotexts.insert(i, processed_result.infotexts[start_index])
|
||||||
|
|
||||||
sub_grid_size = processed_result.images[0].size
|
# sub_grid_size = processed_result.images[0].size
|
||||||
z_grid = images.image_grid(processed_result.images[:z_count], rows=1)
|
z_grid = images.image_grid(processed_result.images[:z_count], rows=1)
|
||||||
|
z_sub_grid_max_w, z_sub_grid_max_h = map(max, zip(*(img.size for img in processed_result.images[:z_count])))
|
||||||
if draw_legend:
|
if draw_legend:
|
||||||
z_grid = images.draw_grid_annotations(z_grid, sub_grid_size[0], sub_grid_size[1], title_texts, [[images.GridAnnotation()]])
|
z_grid = images.draw_grid_annotations(z_grid, z_sub_grid_max_w, z_sub_grid_max_h, title_texts, [[images.GridAnnotation()]])
|
||||||
processed_result.images.insert(0, z_grid)
|
processed_result.images.insert(0, z_grid)
|
||||||
# TODO: Deeper aspects of the program rely on grid info being misaligned between metadata arrays, which is not ideal.
|
# TODO: Deeper aspects of the program rely on grid info being misaligned between metadata arrays, which is not ideal.
|
||||||
# processed_result.all_prompts.insert(0, processed_result.all_prompts[0])
|
# processed_result.all_prompts.insert(0, processed_result.all_prompts[0])
|
||||||
|
|
Loading…
Reference in New Issue