Skip to content

Commit

Permalink
pull the band-aid and get it over with
Browse files Browse the repository at this point in the history
  • Loading branch information
alemelis committed Feb 20, 2023
1 parent a580c34 commit 9c0827b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 0 additions & 25 deletions aspect_ratios.txt

This file was deleted.

3 changes: 0 additions & 3 deletions resolutions.txt

This file was deleted.

30 changes: 30 additions & 0 deletions scripts/sd-webui-ar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
)
Expand Down

0 comments on commit 9c0827b

Please sign in to comment.