Image Transforms
Resize, reformat, and optimize images on demand by appending URL parameters to any Localess asset URL — no extra service required.
Localess asset URLs support on-demand image transformation via query parameters. Append a parameter to any asset CDN URL to get back a resized, reformatted, or quality-adjusted image — without uploading multiple size variants and without a third-party image CDN.
This is useful for responsive images, thumbnails, and format optimization. The transformation happens server-side and the result is cached at the CDN edge.
URL Parameter Reference
Append parameters to any asset URL returned by client.assetLink() or resolveAsset().
| Parameter | Type | Description | Example |
|---|---|---|---|
w | integer > 0 | Target width in pixels | ?w=800 |
h | integer > 0 | Target height in pixels | ?h=600 |
q | integer (1–100) | Output quality (default: 85). Applies to JPEG, WebP, AVIF. Ignored for PNG. | ?q=70 |
f | string | Output format: webp, jpeg, png, or avif. Converts the image to this format. | ?f=webp |
download | flag | Changes Content-Disposition from inline to form-data, forcing a browser download. | ?download |
thumbnail | flag | For animated WebP/GIF: extracts the first frame before resizing. For video: extracts a frame with FFmpeg, then resizes with Sharp. | ?thumbnail |
Resize Behaviour (w / h)
w | h | Behaviour |
|---|---|---|
| ✓ | — | Scale to width, height auto — aspect ratio preserved, no crop |
| — | ✓ | Scale to height, width auto — aspect ratio preserved, no crop |
| ✓ | ✓ | Cover crop — resizes to fill the exact box, excess edges are cropped |
| — | — | No resize — only format/quality re-encoding if f/q provided |
Special Cases
- SVG — always passed through;
w,h, andfare ignored. - Animated WebP or GIF without
thumbnail— passed through unchanged (cannot resize animated files). - Animated WebP or GIF with
thumbnail— first frame extracted, thenw/h/fapply normally. - Video with
w+thumbnail— frame extracted via FFmpeg, then resized with Sharp; output defaults toimage/webp.
Combine parameters with &:
https://my-space.web.app/api/v1/spaces/abc123/assets/hero.jpg?w=1200&q=80&f=webpExamples
Resize to a fixed width
/api/v1/spaces/abc123/assets/hero.jpg?w=800Returns the image at 800 px wide. Height scales proportionally to preserve the aspect ratio.
Resize to a fixed height
/api/v1/spaces/abc123/assets/hero.jpg?h=400Returns the image at 400 px tall. Width scales proportionally.
Crop to exact dimensions
/api/v1/spaces/abc123/assets/hero.jpg?w=800&h=600Returns a 800×600 image using cover crop — the image is scaled to fill the box and excess edges are trimmed. Use this for fixed-size slots like thumbnails or hero banners.
Convert to WebP with quality control
/api/v1/spaces/abc123/assets/product.png?f=webp&q=75Converts a PNG to WebP at 75% quality. Typical file size reduction: 25–40% compared to the original PNG.
Responsive thumbnail
/api/v1/spaces/abc123/assets/blog-cover.jpg?w=400&f=webp&q=80A compact, web-optimized version of a full-size image — suitable for article cards and preview grids.
Using Transforms in Code
@localess/client
Build the transform URL by appending parameters to the result of assetLink():
import { localessClient } from '@localess/client';
const client = localessClient({ spaceId: 'abc123', baseUrl: 'https://my-space.web.app' });
// Base CDN URL
const url = client.assetLink(content.data.heroImage);
// → https://my-space.web.app/api/v1/spaces/abc123/assets/hero.jpg
// With transform
const optimized = `${url}?w=1200&f=webp&q=80`;@localess/react
import { resolveAsset } from '@localess/react';
function HeroImage({ image }: { image: ContentAsset }) {
const baseUrl = resolveAsset(image);
return (
<img
src={`${baseUrl}?w=1200&f=webp&q=80`}
srcSet={[
`${baseUrl}?w=400&f=webp&q=80 400w`,
`${baseUrl}?w=800&f=webp&q=80 800w`,
`${baseUrl}?w=1200&f=webp&q=80 1200w`,
].join(', ')}
sizes="(max-width: 768px) 100vw, 1200px"
alt={image.alt ?? ''}
/>
);
}@localess/angular — automatic with NgOptimizedImage
When you use provideLocalessBrowser(), Angular's NgOptimizedImage (ngSrc) directive automatically appends ?w=<requested-width> to the asset URL based on the width attribute. No manual parameter construction is needed:
<img
ngSrc="{{ data.image | llAsset }}"
width="800"
height="600"
alt="Hero image"
/>
<!-- Rendered src: https://my-space.web.app/api/v1/spaces/abc123/assets/hero.jpg?w=800 -->URL Transforms vs Uploading Pre-Sized Assets
| Approach | Best when |
|---|---|
| URL transforms | You upload once and serve at multiple sizes — responsive images, thumbnails, format variants |
| Pre-sized uploads | You need pixel-perfect control over cropping, or you have assets that are already optimized at a fixed size (icons, logos, print-ready images) |
For most editorial content (blog images, product photos, hero banners) URL transforms are the right default. Upload the highest-quality version of an image once, then let Localess handle resizing and format conversion at request time.
Pre-sized uploads make sense for:
- Art-directed crops (different composition at mobile vs desktop)
- Images where the original quality must be preserved exactly (print, legal documents)
- SVG and other vector formats that do not benefit from raster transforms
Format Recommendations
| Source format | Recommended ?f= value | Reason |
|---|---|---|
| JPEG | webp | 25–35% smaller at equivalent quality |
| PNG (photographic) | webp or avif | Better compression than PNG for photos |
| PNG (transparency needed) | webp or avif | Both support alpha — AVIF offers better compression on modern browsers |
| Already WebP | — | No conversion needed; add ?f=avif to target Chrome/Firefox users |
| Animated GIF/WebP | — | Pass through unless ?thumbnail is set |
Check browser support for your target audience before relying on WebP or AVIF exclusively. For broad compatibility, serve AVIF with a WebP and JPEG fallback using <picture> and <source>.