Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -66,18 +66,18 @@ def calculate_new_dimensions(orig_w, orig_h):
|
|
66 |
"""
|
67 |
Calculates new dimensions for height and width based on original media dimensions.
|
68 |
Rules:
|
69 |
-
1. If any dimension >
|
70 |
2. Then ensure both dimensions are multiples of 32 by rounding to the nearest multiple.
|
71 |
-
3. Ensure dimensions are within [256,
|
72 |
"""
|
73 |
if orig_w == 0 or orig_h == 0:
|
74 |
return TARGET_FIXED_SIDE, TARGET_FIXED_SIDE
|
75 |
|
76 |
# Step 1: Handle dimensions > 1024
|
77 |
new_w, new_h = orig_w, orig_h
|
78 |
-
if max(orig_w, orig_h) >
|
79 |
max_dim = max(orig_w, orig_h)
|
80 |
-
scale =
|
81 |
new_w = int(orig_w * scale)
|
82 |
new_h = int(orig_h * scale)
|
83 |
|
|
|
66 |
"""
|
67 |
Calculates new dimensions for height and width based on original media dimensions.
|
68 |
Rules:
|
69 |
+
1. If any dimension > MAX_IMAGE_SIZE, resize so max dimension is MAX_IMAGE_SIZE, maintaining aspect ratio.
|
70 |
2. Then ensure both dimensions are multiples of 32 by rounding to the nearest multiple.
|
71 |
+
3. Ensure dimensions are within [256, MAX_IMAGE_SIZE].
|
72 |
"""
|
73 |
if orig_w == 0 or orig_h == 0:
|
74 |
return TARGET_FIXED_SIDE, TARGET_FIXED_SIDE
|
75 |
|
76 |
# Step 1: Handle dimensions > 1024
|
77 |
new_w, new_h = orig_w, orig_h
|
78 |
+
if max(orig_w, orig_h) > MAX_IMAGE_SIZE:
|
79 |
max_dim = max(orig_w, orig_h)
|
80 |
+
scale = MAX_IMAGE_SIZE / max_dim
|
81 |
new_w = int(orig_w * scale)
|
82 |
new_h = int(orig_h * scale)
|
83 |
|