Who this is for. Developers who have an image path but no template object: in JavaScript, a stylesheet, an email built elsewhere, or a headless front end reading images through the API. After this page you can write an image URL that does what you expect, and recognise the cases where only the template object can.
The template methods build these URLs; the work happens when a browser requests one. The platform then generates that version of the file, caches it, and serves the cached copy from then on.
The URL shape
Every file is served from /files/ followed by its folder path and name in the file manager, as in /files/images/pages/hero.jpg. Spaces and other special characters in names are URL-encoded: /files/images/pages/Homepage%20carousel.jpg.
The extension in the path is the format you want back. To have a JPEG delivered as WebP, change the extension to .webp and name the original's format in f: /files/images/pages/hero.webp?f=jpg. f tells the platform which file to start from; it is never the target.
The parameters
| Parameter | Type | What it does | Example |
|---|---|---|---|
w | Whole number, pixels | Width. A resize happens only when w or h is present. | hero.jpg?w=800 |
h | Whole number, pixels | Height. | hero.jpg?h=400 |
s | Strategy name | Resize strategy: crop or fit; see below. | hero.jpg?w=600&h=600&s=fit |
x, y | Whole numbers, pixels | The top-left corner of a crop. Only the URL can set these. | hero.jpg?w=1600&h=600&s=crop&x=0&y=200 |
c | Percentage | Scale, used with a crop. Only valid with s=crop. | hero.jpg?w=600&h=600&s=crop&c=50 |
f | jpg, jpeg, png, gif, tif or tiff | The original's format when converting. The target is the path's extension, such as png or webp. | hero.webp?f=jpg |
q | 1 to 100 | Compression quality, in place of the site's Override quality. | hero.jpg?w=800&q=70 |
l | 1 or 0 | Lossy compression on or off, in place of the site's Lossy image optimization. | hero.jpg?l=0 |
r | Revision id | A specific revision of the file, rather than the current one. | hero.jpg?r=1234 |
v | Text | The change-time value getPath() adds when Add change time parameter to URL is on. It changes the URL when the file changes; you do not set it yourself. | hero.jpg?v=… |
Strategy names through the URL
In a URL, give s the value crop or fit, or leave it out to scale: with one dimension the image keeps its aspect ratio, and with both it takes exactly that box. The template's image object works out the final dimensions from any of the seven strategies before it builds the URL (see Resize strategies), so for any other shape, let a template build the URL with getResized() and hand it on, as shown below. For a fitted size in a hand-written URL, compute it yourself: for a 2:1 image inside a 300 × 300 box, ask for ?w=300&h=150.
Worked URLs
A width-constrained thumbnail, tested on this site:
/files/images/api-sandbox/api-sandbox-figure.png?w=300
A JPEG filled into a carousel slot and delivered as WebP, taken from a live site. It is what getResized(1065, 600, 'fit')->toOptimizedFormat() produced in a template:
/files/images/pages/Homepage%20carousel.webp?w=1065&h=600&s=fit&f=jpg
A PNG logo converted to WebP and not resized, from a live site (file name generalised):
/files/images/pages/1/site-logo.webp?f=png
A fallback image swapped in from JavaScript, from a live site: