From 9c0827baf0b3abfff48a207226f414b7d53c4bbc Mon Sep 17 00:00:00 2001 From: alemelis Date: Mon, 20 Feb 2023 08:55:04 +0000 Subject: [PATCH] pull the band-aid and get it over with --- README.md | 8 ++++++-- aspect_ratios.txt | 25 ------------------------- resolutions.txt | 3 --- scripts/sd-webui-ar.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 30 deletions(-) delete mode 100644 aspect_ratios.txt delete mode 100644 resolutions.txt diff --git a/README.md b/README.md index 379ba3f..6a6a05f 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ Extension for [AUTOMATIC1111/stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui.git) adding image aspect ratio selector buttons. +## Updates + +- 20/02/2023 :warning: this update will remove your local config files (`aspect_ratios.txt` and `resolutions.txt`) and it will create new default ones. These can be then modified freely and preserved in the future. For more info read [here](https://github.com/alemelis/sd-webui-ar/issues/9). + ## Install Browse to the `Extensions` tab -> go to `Install from URL` -> paste in `https://github.com/alemelis/sd-webui-ar` -> click `Install` @@ -18,7 +22,7 @@ Here's how the UI looks like after installing this extension ### Configuration -Aspect ratios can be defined in the `/sd-webui-ar/aspect_ratios.txt` file. The file is pre-populated with the most common values +Aspect ratios can be defined in the `/sd-webui-ar/aspect_ratios.txt` file. For example, ``` 1:1, 1.0 @@ -52,7 +56,7 @@ Note the `#` marking the line as a comment, i.e. the extension is not reading th A custom aspect ratio is defined as `button-label, aspect-ratio-value # comment`. The `aspect-ratio-value` must be a number (either `float` or `int`) while the `# comment` is optional. The `button-label` will be displayed inside the button. It can be anything you like. -Resolutions are defined inside `resolutions.txt` file. By default this reads +Resolutions presets are defined inside `resolutions.txt` file, ``` 1, 512, 512 # 1:1 square diff --git a/aspect_ratios.txt b/aspect_ratios.txt deleted file mode 100644 index 5c26b40..0000000 --- a/aspect_ratios.txt +++ /dev/null @@ -1,25 +0,0 @@ -1:1, 1.0 -3:2, 1.5 -4:3, 1.333 -16:9, 1.777 -# 6:13, 0.461538 -# 9:16, 0.5625 -# 3:5, 0.6 -# 2:3, 0.666 -# 19:16, 1.19 # fox movietone -# 5:4, 1.25 # medium format photo -# 11:8, 1.375 # academy standard -# IMAX, 1.43 -# 14:9, 1.56 -# 16:10, 1.6 -# 𝜑, 1.6180 # golden ratio -# 5:3, 1.6666 # super 16mm -# 1.85, 1.85 # US widescreen cinema -# DCI, 1.9 # digital imax -# 2:1, 2.0 # univisium -# 70mm, 2.2 -# 21:9, 2.370 # cinematic wide screen -# δ, 2.414 # silver ratio -# UPV70, 2.76 # ultra panavision 70 -# 32:9, 3.6 # ultra wide screen -# PV, 4.0 # polyvision diff --git a/resolutions.txt b/resolutions.txt deleted file mode 100644 index 3ccf8ce..0000000 --- a/resolutions.txt +++ /dev/null @@ -1,3 +0,0 @@ -1, 512, 512 # 1:1 square -2, 768, 512 # 3:2 landscape -3, 403, 716 # 9:16 portrait diff --git a/scripts/sd-webui-ar.py b/scripts/sd-webui-ar.py index 7d5c998..1ef9f6d 100644 --- a/scripts/sd-webui-ar.py +++ b/scripts/sd-webui-ar.py @@ -100,8 +100,34 @@ def parse_resolutions_file(filename): return labels, values, comments +# TODO: write a generic function handling both cases +def write_aspect_ratios_file(filename): + aspect_ratios = [ + "1:1, 1.0\n", + "3:2, 1.5\n", + "4:3, 1.333\n", + "16:9, 1.777", + ] + with open(filename, "w", encoding="utf-8") as f: + f.writelines(aspect_ratios) + + +def write_resolutions_file(filename): + resolutions = [ + "1, 512, 512 # 1:1 square\n", + "2, 768, 512 # 3:2 landscape\n", + "3, 403, 716 # 9:16 portrait", + ] + with open(filename, "w", encoding="utf-8") as f: + f.writelines(resolutions) + + class AspectRatioScript(scripts.Script): def read_aspect_ratios(self): + ar_file = Path(aspect_ratios_dir, "aspect_ratios.txt") + if not ar_file.exists(): + write_aspect_ratios_file(ar_file) + ( self.aspect_ratio_labels, aspect_ratios, @@ -117,6 +143,10 @@ def read_aspect_ratios(self): # see https://github.com/alemelis/sd-webui-ar/issues/5 def read_resolutions(self): + res_file = Path(aspect_ratios_dir, "resolutions.txt") + if not res_file.exists(): + write_resolutions_file(res_file) + self.res_labels, res, self.res_comments = parse_resolutions_file( "resolutions.txt" )