Spaces:
Running on Zero
Running on Zero
File size: 571 Bytes
2837b03 9fcf338 2837b03 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | MAX_OUTPUT_DIM = 2048
MAX_OUTPUT_DIM_FAST = 768
def compute_output_dimensions(w, h, max_dim=MAX_OUTPUT_DIM):
# Pin the long side to max_dim and scale the short side proportionally.
# We snap to the nearest multiple of 8 (not floor) to minimise aspect ratio
# distortion: floor always undershoots, whereas rounding keeps the error
# within ±4px, which halves the worst-case ratio deviation.
if w > h:
nw = max_dim
nh = round(nw * h / w / 8) * 8
else:
nh = max_dim
nw = round(nh * w / h / 8) * 8
return nw, nh
|