Update app.py
Browse files
app.py
CHANGED
|
@@ -57,22 +57,30 @@ def get_pipe():
|
|
| 57 |
return pipe
|
| 58 |
|
| 59 |
# -------------------------
|
| 60 |
-
# IMAGE RESIZE
|
| 61 |
# -------------------------
|
| 62 |
def resize_image(image: Image.Image) -> Image.Image:
|
| 63 |
width, height = image.size
|
| 64 |
if width == height:
|
| 65 |
-
|
| 66 |
-
aspect_ratio = width / height
|
| 67 |
-
if width > height:
|
| 68 |
-
target_w = MAX_DIM
|
| 69 |
-
target_h = int(target_w / aspect_ratio)
|
| 70 |
else:
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
# -------------------------
|
| 78 |
# VIDEO GENERATION
|
|
|
|
| 57 |
return pipe
|
| 58 |
|
| 59 |
# -------------------------
|
| 60 |
+
# IMAGE RESIZE (16-multiple)
|
| 61 |
# -------------------------
|
| 62 |
def resize_image(image: Image.Image) -> Image.Image:
|
| 63 |
width, height = image.size
|
| 64 |
if width == height:
|
| 65 |
+
w = h = SQUARE_DIM
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
else:
|
| 67 |
+
aspect_ratio = width / height
|
| 68 |
+
if width > height:
|
| 69 |
+
w = MAX_DIM
|
| 70 |
+
h = int(w / aspect_ratio)
|
| 71 |
+
else:
|
| 72 |
+
h = MAX_DIM
|
| 73 |
+
w = int(h * aspect_ratio)
|
| 74 |
+
|
| 75 |
+
# Pyöristetään 16:lla jaolliseksi
|
| 76 |
+
w = (w // 16) * 16
|
| 77 |
+
h = (h // 16) * 16
|
| 78 |
+
|
| 79 |
+
# Clamp min/max
|
| 80 |
+
w = max(MIN_DIM, min(MAX_DIM, w))
|
| 81 |
+
h = max(MIN_DIM, min(MAX_DIM, h))
|
| 82 |
+
|
| 83 |
+
return image.resize((w, h), Image.LANCZOS)
|
| 84 |
|
| 85 |
# -------------------------
|
| 86 |
# VIDEO GENERATION
|