Resize Modes
Control how images are resized with different modes.
The r parameter controls how images are resized. Each mode handles aspect ratio and cropping differently.
Modes
fit (default)
Scales the image to fit inside the specified dimensions while maintaining the aspect ratio. The output may be smaller than the requested dimensions.
?w=400&h=300&r=fit
A 1600x1200 image becomes 400x300. A 1600x900 image becomes 400x225 (maintains 16:9).
scale
Resizes to the exact dimensions, distorting the image if the aspect ratio doesn't match.
?w=400&h=300&r=scale
The output is always exactly 400x300, regardless of the original aspect ratio.
fill
Covers the specified dimensions, cropping edges that extend beyond the bounds. The crop is centered by default.
?w=400&h=300&r=fill
A 1600x900 image is scaled and center-cropped to exactly 400x300.
crop
Extracts a region of the specified dimensions from the image. Supports compass gravity and facial gravity for positioning.
?w=400&h=300&r=crop&g=north
Both w and h are required for crop mode.
thumb
Generates a thumbnail with smart cropping. When combined with facial gravity (g=face), it uses face detection to center the crop on the most prominent face.
?w=200&h=200&r=thumb&g=face
Both w and h are required for thumb mode.
Dimension Defaults
| Provided | Default Resize Mode |
|---|---|
Both w and h | scale |
Only w or h | fit |
| Neither | No resize (original dimensions) |
Single Dimension
When only one dimension is provided, the other is calculated to maintain the aspect ratio:
?w=400 # Height calculated proportionally
?h=300 # Width calculated proportionally
Format-Specific Limits
WebP and AVIF formats have a maximum dimension of 2000px. If the output would exceed this limit:
- In
fitmode, the image is scaled down to fit within 2000px - In
croporscalemode, an error is returned
Examples
# Fit a hero image into 1200x600
?w=1200&h=600&r=fit
# Exact 400x400 square avatar
?w=400&h=400&r=fill
# Crop from the top of the image
?w=800&h=400&r=crop&g=north
# Face-centered thumbnail
?w=150&h=150&r=thumb&g=face