mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
feat: use available aspect ratios from config, move function to util, change default visibility of label
This commit is contained in:
+1
-1
@@ -514,7 +514,7 @@ def add_ratio(x):
|
||||
|
||||
|
||||
default_aspect_ratio = add_ratio(default_aspect_ratio)
|
||||
available_aspect_ratios = [add_ratio(x) for x in available_aspect_ratios]
|
||||
available_aspect_ratios_labels = [add_ratio(x) for x in available_aspect_ratios]
|
||||
|
||||
|
||||
# Only write config in the first launch.
|
||||
|
||||
@@ -123,7 +123,7 @@ def get_resolution(key: str, fallback: str | None, source_dict: dict, results: l
|
||||
h = source_dict.get(key, source_dict.get(fallback, default))
|
||||
width, height = eval(h)
|
||||
formatted = modules.config.add_ratio(f'{width}*{height}')
|
||||
if formatted in modules.config.available_aspect_ratios:
|
||||
if formatted in modules.config.available_aspect_ratios_labels:
|
||||
results.append(formatted)
|
||||
results.append(-1)
|
||||
results.append(-1)
|
||||
|
||||
@@ -392,3 +392,25 @@ def makedirs_with_log(path):
|
||||
|
||||
def get_enabled_loras(loras: list) -> list:
|
||||
return [[lora[1], lora[2]] for lora in loras if lora[0]]
|
||||
|
||||
|
||||
def get_image_size_info(image: np.ndarray, available_aspect_ratios: list) -> str:
|
||||
try:
|
||||
image = Image.fromarray(np.uint8(image))
|
||||
width, height = image.size
|
||||
ratio = round(width / height, 2)
|
||||
gcd = math.gcd(width, height)
|
||||
lcm_ratio = f'{width // gcd}:{height // gcd}'
|
||||
size_info = f'Image Size: {width} x {height}, Ratio: {ratio}, {lcm_ratio}'
|
||||
|
||||
closest_ratio = min(available_aspect_ratios, key=lambda x: abs(ratio - float(x.split('*')[0]) / float(x.split('*')[1])))
|
||||
recommended_width, recommended_height = map(int, closest_ratio.split('*'))
|
||||
recommended_ratio = round(recommended_width / recommended_height, 2)
|
||||
recommended_gcd = math.gcd(recommended_width, recommended_height)
|
||||
recommended_lcm_ratio = f'{recommended_width // recommended_gcd}:{recommended_height // recommended_gcd}'
|
||||
|
||||
size_info += f'\nRecommended Size: {recommended_width} x {recommended_height}, Ratio: {recommended_ratio}, {recommended_lcm_ratio}'
|
||||
|
||||
return size_info
|
||||
except Exception as e:
|
||||
return f'Error reading image: {e}'
|
||||
|
||||
Reference in New Issue
Block a user