Commit
·
b18bc5f
1
Parent(s):
52decb6
Fix: auto-detect portrait/landscape orientation for proper aspect ratio
Browse files
app.py
CHANGED
|
@@ -40,8 +40,22 @@ default_negative_prompt = "low quality, worst quality, blurry, distorted, deform
|
|
| 40 |
# IMAGE RESIZING LOGIC
|
| 41 |
# =========================================================
|
| 42 |
|
| 43 |
-
def resize_image(image: Image.Image
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# =========================================================
|
| 47 |
# MAIN GENERATION FUNCTION
|
|
|
|
| 40 |
# IMAGE RESIZING LOGIC
|
| 41 |
# =========================================================
|
| 42 |
|
| 43 |
+
def resize_image(image: Image.Image) -> Image.Image:
|
| 44 |
+
width, height = image.size
|
| 45 |
+
aspect_ratio = width / height
|
| 46 |
+
|
| 47 |
+
# SVD works best with 1024x576 or 576x1024
|
| 48 |
+
if aspect_ratio > 1: # Landscape
|
| 49 |
+
new_width = 1024
|
| 50 |
+
new_height = 576
|
| 51 |
+
elif aspect_ratio < 1: # Portrait
|
| 52 |
+
new_width = 576
|
| 53 |
+
new_height = 1024
|
| 54 |
+
else: # Square
|
| 55 |
+
new_width = 768
|
| 56 |
+
new_height = 768
|
| 57 |
+
|
| 58 |
+
return image.resize((new_width, new_height), Image.LANCZOS)
|
| 59 |
|
| 60 |
# =========================================================
|
| 61 |
# MAIN GENERATION FUNCTION
|