Sizing Rules

Last updated


This page explains how GetNewSize turns s, w, and h into output dimensions, and the default downscale applied when no size parameter is given.

Rules


Conditions are checked top to bottom; only the first match applies:
ConditionOutput
s setShort edge scaled to min(s, original short edge), long edge proportional
Both w and h setScale factor from min(w, original width), whole image scaled proportionally
Only wWidth scaled to min(w, original width), height proportional
Only hHeight scaled to min(h, original height), width proportional
None, and original short edge > 1024 pxLong edge scaled to 1024 px, short edge proportional
OtherwiseOriginal dimensions

No rule ever upscales the original.

Edge Cases


CaseResultWhy
w and h both setActual height is original height × (new width ÷ original width); h has no effect on outputResize takes a single scale factor, newWidth / originWidth
s / w / h not an integerOriginal dimensions, the 1024 px default is not appliedA non-empty parameter enters its branch; after strconv.Atoi fails no further rule is checked
Original short edge ≤ 1024 px, no size parameterOriginal dimensions, still converted to the t formatThe default rule targets large images only

Examples


For a 4000 × 3000 original:
Request parametersOutput size
(none)1024 × 768
s=480640 × 480
w=800800 × 600
h=300400 × 300
w=800&h=200800 × 600
s=50004000 × 3000
中文