Image Transformation
img-src provides powerful on-demand image transformation through URL parameters. Images are transformed at the edge and cached for optimal performance.Basic URL Structure
Transformation Parameters
Quick Reference
Size & Layout
| Parameter | Description | Values | Example |
|---|---|---|---|
w | Width in pixels | 1-10000 | ?w=800 |
h | Height in pixels | 1-10000 | ?h=600 |
fit | Fit mode | cover, contain, fill, scale-down | ?fit=cover |
aspect | Aspect ratio | original, 1:1, 4:3, 16:9, 3:2, 21:9 | ?aspect=16:9 |
Quality & Display
| Parameter | Description | Values | Example |
|---|---|---|---|
q | Quality (compression) | 1-100 (default: 80) | ?q=85 |
dpr | Device pixel ratio (Retina) | 1, 1.5, 2, 3 | ?dpr=2 |
crop | Crop position | center, top, bottom, left, right, attention, entropy | ?crop=attention |
grayscale | Convert to grayscale | true, false | ?grayscale=true |
Effects & Transform
| Parameter | Description | Values | Example |
|---|---|---|---|
blur | Gaussian blur | 0-100 | ?blur=10 |
sharpen | Sharpen intensity | 0-100 | ?sharpen=15 |
rotate | Rotation angle | 0, 90, 180, 270, auto | ?rotate=90 |
flip | Flip/mirror | h, v, both | ?flip=h |
Presets (Pro)
| Parameter | Description | Values | Example |
|---|---|---|---|
p:name | Apply preset | Preset name | ?p:thumbnail |
Width & Height
Resize images by specifying width (w) and/or height (h) in pixels:
Fit Mode
Control how the image fits within the specified dimensions:| Mode | Description |
|---|---|
cover | Fill dimensions, cropping if needed (default) |
contain | Fit within dimensions, preserving aspect ratio |
fill | Stretch to fill dimensions exactly |
scale-down | Like contain, but never upscale |
Visual comparison of fit modes
Visual comparison of fit modes
| Original (4:3) | cover | contain | fill |
|---|---|---|---|
| 400x300 | Cropped to 200x200 | 200x150 | Stretched to 200x200 |
Quality
Adjust compression quality (1-100, default: 80):Output Format
The output format is determined by the file extension in the URL. You can serve the original format without conversion, or convert to a different format.| Format | Extension | Best For |
|---|---|---|
| Original | (same as uploaded) | No conversion, fastest delivery |
| WebP | .webp | General use, best compression |
| AVIF | .avif | Maximum compression |
| JPEG | .jpg, .jpeg | Universal compatibility |
| PNG | .png | Transparency, lossless |
Aspect Ratio
Constrain the output to a specific aspect ratio:original, 1:1, 4:3, 16:9, 3:2, 21:9
DPR (Device Pixel Ratio)
Serve higher resolution images for Retina displays:1, 1.5, 2, 3
Crop Position
Control where the crop occurs when usingfit=cover:
| Value | Description |
|---|---|
center | Center of the image (default) |
top, bottom, left, right | Edge positions |
top-left, top-right, bottom-left, bottom-right | Corner positions |
attention | Auto-detect important area (faces, objects) |
entropy | Area with highest visual complexity |
Grayscale
Convert images to black and white:Blur
Apply Gaussian blur (0-100):Sharpen
Increase image sharpness (0-100):Rotate
Rotate the image:0, 90, 180, 270, auto
Flip
Mirror the image horizontally or vertically:Combining Parameters
Chain multiple parameters with&:
Using Presets (Pro)
Pro users can save transformation configurations as presets:Responsive Images
Usesrcset for responsive images:
Supported Input Formats
img-src accepts these input formats:- Common: JPEG, PNG, WebP, GIF
- Professional: TIFF, BMP, ICO, SVG
- Modern: HEIC/HEIF, AVIF
- Specialized: TGA, PNM, QOI, HDR, EXR
Caching
Transformed images are cached at the edge:- First request: Image is fetched, transformed, and cached
- Subsequent requests: Served directly from cache
- Cache duration: 30 days (configurable)
- The original image is updated
- The image is deleted
- You call the purge API endpoint
Cache Headers
Responses include standard cache headers:If-None-Match header with the ETag for conditional requests.
Best Practices
Use appropriate quality settings
Use appropriate quality settings
- Hero/banner images: 85-90
- Product images: 80-85
- Thumbnails: 60-75
- Backgrounds: 70-80
Let the browser choose format
Let the browser choose format
Use the file extension in your URL to specify the output format (e.g.,
.webp, .avif). img-src will convert your image to that format automatically.Use fit=scale-down for unknown sizes
Use fit=scale-down for unknown sizes
Prevents small images from being upscaled and looking blurry.
Create presets for common sizes
Create presets for common sizes
Pro users should create presets for frequently used transformations to simplify URLs and ensure consistency.