# Sizing Rules

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:

| Condition | Output |
|---|---|
| `s` set | Short edge scaled to `min(s, original short edge)`, long edge proportional |
| Both `w` and `h` set | Scale factor from `min(w, original width)`, whole image scaled proportionally |
| Only `w` | Width scaled to `min(w, original width)`, height proportional |
| Only `h` | Height scaled to `min(h, original height)`, width proportional |
| None, and original short edge > 1024 px | Long edge scaled to 1024 px, short edge proportional |
| Otherwise | Original dimensions |

No rule ever upscales the original.

## Edge Cases

| Case | Result | Why |
|---|---|---|
| `w` and `h` both set | Actual height is `original height × (new width ÷ original width)`; `h` has no effect on output | `Resize` takes a single scale factor, `newWidth / originWidth` |
| `s` / `w` / `h` not an integer | Original dimensions, the 1024 px default is **not** applied | A non-empty parameter enters its branch; after `strconv.Atoi` fails no further rule is checked |
| Original short edge ≤ 1024 px, no size parameter | Original dimensions, still converted to the `t` format | The default rule targets large images only |

## Examples

For a 4000 × 3000 original:

| Request parameters | Output size |
|---|---|
| (none) | 1024 × 768 |
| `s=480` | 640 × 480 |
| `w=800` | 800 × 600 |
| `h=300` | 400 × 300 |
| `w=800&h=200` | 800 × 600 |
| `s=5000` | 4000 × 3000 |
