From 17b24e45e8839d889af35ee0b2fb0825306ddafe Mon Sep 17 00:00:00 2001 From: Francesco Manzali Date: Tue, 31 Jan 2023 18:58:36 +0100 Subject: [PATCH] Fix prompt matrix #rows/#cols when using hires - images.draw_prompt_matrix() should be called with the final width/height of the generated images, after upscaling. Otherwise, the number of rows/cols computed in images.draw_grid_annotations will increase by the upscaling factor. - Round the number of cols/rows in images.draw_grid_annotations, since the final images width may be a bit less than the required hr_upscale_to_x/y --- modules/images.py | 4 ++-- scripts/prompt_matrix.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/images.py b/modules/images.py index ae3cdaf4a..4be0e74dd 100644 --- a/modules/images.py +++ b/modules/images.py @@ -171,8 +171,8 @@ def draw_grid_annotations(im, width, height, hor_texts, ver_texts): pad_left = 0 if sum([sum([len(line.text) for line in lines]) for lines in ver_texts]) == 0 else width * 3 // 4 - cols = im.width // width - rows = im.height // height + cols = round(im.width / width) + rows = round(im.height / height) assert cols == len(hor_texts), f'bad number of horizontal texts: {len(hor_texts)}; must be {cols}' assert rows == len(ver_texts), f'bad number of vertical texts: {len(ver_texts)}; must be {rows}' diff --git a/scripts/prompt_matrix.py b/scripts/prompt_matrix.py index dd95e5887..f6575b6b3 100644 --- a/scripts/prompt_matrix.py +++ b/scripts/prompt_matrix.py @@ -79,7 +79,7 @@ class Script(scripts.Script): processed = process_images(p) grid = images.image_grid(processed.images, p.batch_size, rows=1 << ((len(prompt_matrix_parts) - 1) // 2)) - grid = images.draw_prompt_matrix(grid, p.width, p.height, prompt_matrix_parts) + grid = images.draw_prompt_matrix(grid, max(p.width, p.hr_upscale_to_x), max(p.height, p.hr_upscale_to_y), prompt_matrix_parts) processed.images.insert(0, grid) processed.index_of_first_image = 1 processed.infotexts.insert(0, processed.infotexts[0])