Skip to main content
Responsive images usually solve one of two problems: resolution switching (same composition, different pixel widths) or art direction (different crop, aspect ratio, or focal point per viewport). Convertly handles both from a single source file — you change URL parameters, not maintain separate exports.
Prerequisites: a CDN endpoint and either Convertly Storage file IDs or a configured origin source. Install @convertly-sh/image before using the React examples below.

Resolution switching vs art direction

Rule of thumb: if only the pixel width changes, use <ConvertlyImage>. If the composition changes, use <picture>.
Art-directed picture element crops at desktop, tablet, phablet, and mobile breakpoints

One source image — four <picture> breakpoints with different aspect ratios and fit=cover crops.

Resize your browser or use DevTools device mode to see how <picture> picks the matching <source>. Chrome may fetch twice in the inspector — that is a tooling quirk, not double-loading in production.

<ConvertlyCdnProvider> — configure once

<ConvertlyCdnProvider> is a React context wrapper that creates one shared CDN client (createConvertlyCdn) for every <ConvertlyImage> and <ConvertlyVideo> underneath it.
What it stores Why use it
  • DRY config — set namespace once in your root layout instead of on every image.
  • Single CDN instance — avoids recreating the URL builder on every render.
  • Composable — child components call <ConvertlyImage src="…" /> without knowing env vars.
When you can skip it Pass namespace directly on <ConvertlyImage>, or use the framework-agnostic createConvertlyCdn() in Astro, Svelte, or plain HTML. Vue uses provideConvertlyCdn() for the same pattern; Solid uses <ConvertlyCdnProvider> identically to React.
Use NEXT_PUBLIC_CONVERTLY_CDN_NAMESPACE (your CDN endpoint’s public URL namespace), never a secret cvly_… API key. Namespace values are safe in client bundles; API keys are not.

Resolution switching with <ConvertlyImage>

<ConvertlyImage> renders a real <img> with Convertly CDN URLs. When you pass width and sizes, it automatically builds a responsive srcSet using defaultWidths() and sets format=auto + gravity=auto by default.
320 pixel wide vs 1200 pixel wide responsive srcset candidates side by side

Same composition, different widths — the browser picks a srcset candidate (320w left, 1200w right).

That produces markup equivalent to:

Origin-backed images

For assets on a registered origin source (e.g. deployed public/ folder):

Custom width lists

Override the default breakpoint ladder when your layout needs specific steps:

Next.js: global loader instead of per-component markup

If you use next/image everywhere, wire createConvertlyLoader once — every <Image> gets CDN URLs without switching to <ConvertlyImage>. Use <ConvertlyImage> when you need transform props (preset, text overlays, gravity=face) that next/image does not pass through.

Art direction with <picture>

Use <picture> when the crop or aspect ratio should change at a breakpoint — for example a wide landscape hero on desktop and a tall portrait crop on mobile. Convertly does not ship a <ConvertlyPicture> component today. Build <picture> with the URL builder; each <source> gets its own transform params.

Plain HTML

Replace {endpointNamespace} and {fileIdOrSlug} with your values:
One origin image. Four CDN URLs. Each variant is generated on demand and cached at the edge.
Wide hero source image before art-directed cropsFour art-directed crops for picture element breakpoints

Source landscape (top) — the same file reframed at each breakpoint below.

React with the URL builder

If you already use <ConvertlyCdnProvider>, call useConvertlyCdn() inside child components instead of creating a second client:

Adding srcset per breakpoint

For art-directed sources that also need multiple widths within a breakpoint, combine cdn.srcset() on each <source>:

Automated cropping for art direction

When the subject is not centred, pick a gravity mode per breakpoint instead of pre-cropping assets:
Center crop vs face-aware crop on a team photo

Portrait square crop — gravity=center (left) vs gravity=face (right) on a group photo.

See Smart cropping & image analysis for focal points, the analyze endpoint, and before/after examples.

Retina and high-DPI screens

Convertly uses width descriptors in srcset (320w, 640w, …). The browser picks a URL whose width matches the rendered size × device pixel ratio. You do not need separate 1x / 2x density descriptors — include widths up to ~2× your layout width (which defaultWidths() does automatically). Alternative: fixed layout width + dpr=2 on the URL. See Device pixel ratio and Client Hints when the slot width is fluid. Example: an image displayed at 600px CSS width on a 2× screen may request the 1200w candidate from the set.
Small and large srcset width candidates for retina displays

Width descriptors cover retina — a 600px layout slot on a 2× display typically selects the 1200w URL from the generated set.

Quick reference

Last modified on July 17, 2026