From b68592dee901c14fa314d2a83f181d9734fce5d7 Mon Sep 17 00:00:00 2001 From: Gerschel Date: Sat, 4 Feb 2023 16:08:55 -0800 Subject: [PATCH] added dimension setting for user to specify base Modified aspect ratio resize to use user preferred dimension Included setting next to aspect ratio inputs. --- modules/shared.py | 1 + modules/ui.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/shared.py b/modules/shared.py index 7d8116fb..be5d75d0 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -466,6 +466,7 @@ options_templates.update(options_section(('ui', "User interface"), { "quicksettings": OptionInfo("sd_model_checkpoint", "Quicksettings list"), "ui_reorder": OptionInfo(", ".join(ui_reorder_categories), "txt2img/img2img UI item order"), "aspect_ratios": OptionInfo(", ".join(aspect_ratio_defaults), "txt2img/img2img aspect ratios"), + "aspect_ratio_base": OptionInfo("width", "aspect ratio base dimension (width or height)"), "ui_extra_networks_tab_reorder": OptionInfo("", "Extra networks tab order"), "localization": OptionInfo("None", "Localization (requires restart)", gr.Dropdown, lambda: {"choices": ["None"] + list(localization.localizations.keys())}, refresh=lambda: localization.list_localizations(cmd_opts.localizations_dir)), })) diff --git a/modules/ui.py b/modules/ui.py index 59f00d6e..715ad664 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -429,13 +429,13 @@ def aspect_ratio_list(): def aspect_ratio_resize(w, h, bttn_val): + dimension = shared.opts.aspect_ratio_base width, height = map(int, bttn_val.split(":")) ratio = width / height - if w / ratio > h: - return (round(h * ratio), h) - else: + if dimension == 'width': return (w, round(w / ratio)) - + elif dimension == 'height': + return (round(h * ratio), h) def get_value_for_setting(key):