Sizing Rules
Last updated
This page explains how s, w, and h translate into output dimensions, including the default downscale and edge cases.
Computation
Given an original of width W and height H, every target is capped at the original dimensions; images are never upscaled.
| Parameters | Landscape (W > H) |
Portrait or square (W ≤ H) |
|---|---|---|
s |
height = min(s, H), width proportional |
width = min(s, W), height proportional |
w and h |
width = min(w, W), height = min(h, H), center-cropped with sharp's default cover |
Same |
Only w |
width = min(w, W), height proportional |
Same |
Only h |
height = min(h, H), width proportional |
Same |
None, and min(W, H) > 1024 |
width = 1024, height proportional | height = 1024, width proportional |
None, and min(W, H) ≤ 1024 |
Original size | Original size |
The proportional edge is rounded down with Math.floor.
Examples
| Original | Parameters | Output |
|---|---|---|
| 4000×3000 | none | 1024×768 |
| 3000×800 | none | 3000×800 (short edge not above 1024) |
| 4000×3000 | s=480 |
640×480 |
| 4000×3000 | w=800 |
800×600 |
| 4000×3000 | w=400&h=400 |
400×400 (cropped) |
| 600×400 | w=1200 |
600×400 (no upscale) |
Edge Cases
| Case | Result |
|---|---|
Non-numeric (w=abc) |
Computes NaN; sharp throws and the 404 image is returned |
s together with w/h |
Only s is used |
w=800&h=0 |
Height is 0; sharp throws and the 404 image is returned |
.pdf / .svg, o=1 |
No resizing |