pull the band-aid and get it over with

This commit is contained in:
alemelis
2023-02-20 08:55:04 +00:00
parent a580c34aa7
commit 9c0827baf0
4 changed files with 36 additions and 30 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -1,3 +0,0 @@
1, 512, 512 # 1:1 square
2, 768, 512 # 3:2 landscape
3, 403, 716 # 9:16 portrait

View File

@@ -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 @@ class AspectRatioScript(scripts.Script):
# 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"
)