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