> For the complete Lynkow documentation index in agent-friendly format, see [llms.txt](/llms.txt).

# Media & Image Optimization

**Publié le** : 2026-11-30
**Catégorie** : Media & SEO

> **Reference** - This guide is a tutorial. For exhaustive, always-current signatures and field lists, see the auto-generated reference:
> 
> - SDK: [`MediaHelperService`](/sdk/services/sdk-media-helper-service)
> - Types: [SDK Types](/sdk/types) (`ImageVariants`, `SrcsetOptions`, `TransformOptions`)
> - API: [Storefront: Content](/storefront-api/storefront-content)

## Prerequisites

- A Lynkow client in `@/lib/lynkow` ([Add Lynkow to an existing project](/sdk/getting-started/existing-project))
- For the Next.js loader: `@lynkow/next` installed

## Variants or transforms

Lynkow media is served by the Lynkow CDN, which resizes images from the URL. You get resized images two ways:

- Ready-made variants on the API response: `featuredImageVariants` and `ogImageVariants`.
- `lynkow.media.srcset()` and `lynkow.media.transform()`, which build resize URLs locally. They make no request and work on the server and in the browser.

Use a variant when one fixed size fits the layout, `srcset()` when the browser should pick a width, and `transform()` for any other size or crop.

## Pre-computed variants

An article with a `featuredImage` carries `featuredImageVariants`, with these presets:

| Preset | Size |
| --- | --- |
| `thumbnail` | 400px wide |
| `card` | 600px wide |
| `medium` | 960px wide |
| `content` | 1200px wide |
| `hero` | 1920px wide |
| `og` | 1200x630, cropped to fill |


The width presets keep the aspect ratio and never upscale. `ogImageVariants` carries only `og`, built from the article's `ogImage`. Any preset can be absent, so keep the original URL as a fallback:

```tsx
<img
  src={article.featuredImageVariants?.hero ?? article.featuredImage}
  alt={article.featuredImageAlt ?? ''}
  className="h-[60vh] w-full object-cover"
  fetchPriority="high"
/>
```

A width preset fixes only the width: a portrait source stays portrait. Frame it in your layout with CSS `aspect-ratio` and `object-fit: cover`.

## Responsive images with `srcset()`

`srcset()` returns one URL per width, ready for the `srcSet` attribute. Pair it with `sizes`, which tells the browser how wide the image renders:

```tsx
// components/responsive-image.tsx
import { lynkow } from '@/lib/lynkow'

export function ResponsiveImage({
  src,
  alt,
  sizes = '(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw',
  priority = false,
}: {
  src: string
  alt: string
  sizes?: string
  priority?: boolean
}) {
  return (
    <img
      src={lynkow.media.transform(src, { w: 800 })}
      srcSet={lynkow.media.srcset(src, { widths: [400, 800, 1200, 1920] }) || undefined}
      sizes={sizes}
      alt={alt}
      loading={priority ? 'eager' : 'lazy'}
      decoding="async"
    />
  )
}
```

`srcset()` accepts `widths` (default `[400, 800, 1200, 1920]`), `fit` (default `'scale-down'`), `quality` (1 to 100, default `80`) and `gravity`. It returns `''` for a URL that is not Lynkow media, hence the `|| undefined`. `transform()` returns such a URL unchanged.

## One size or crop with `transform()`

`transform()` accepts `w`, `h`, `fit`, `quality`, `format` (`'auto'`, `'webp'`, `'avif'` or `'jpeg'`, default `'auto'`, which serves WebP or AVIF to browsers that accept them), `gravity` and `dpr` (1 to 4).

`fit` takes `'scale-down'` (default, keeps the ratio, never upscales), `'contain'`, `'cover'` (fills the box and crops) or `'crop'`. Combine `cover` crops in a `<picture>` for art direction:

```tsx
<picture>
  <source media="(min-width: 1024px)" srcSet={lynkow.media.transform(src, { w: 1920, h: 640, fit: 'cover' })} />
  <source media="(min-width: 640px)" srcSet={lynkow.media.transform(src, { w: 1024, h: 768, fit: 'cover' })} />
  <img src={lynkow.media.transform(src, { w: 640, h: 640, fit: 'cover' })} alt={alt} />
</picture>
```

### Focal point

With `fit: 'cover'` or `'crop'`, `gravity` sets the part of the image the crop keeps. Give it as `XxY` fractions from the top-left corner, or `'face'` to center on a detected face. Without it, the crop is centered.

```typescript
const banner = lynkow.media.transform(photo, { w: 800, h: 400, fit: 'cover', gravity: '0.5x0.3' })
const avatar = lynkow.media.transform(photo, { w: 128, h: 128, fit: 'cover', gravity: 'face' })
```

## Next.js `<Image>` loader

`@lynkow/next/image-loader` makes `next/image` resize Lynkow media on the Lynkow CDN instead of on your server. Next.js requires a loader file, so re-export it:

```typescript
// src/image-loader.ts
export { default } from '@lynkow/next/image-loader'
```

```typescript
// next.config.ts
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  images: { loader: 'custom', loaderFile: './src/image-loader.ts' },
}

export default nextConfig
```

`<Image>` then works as usual, with `width`, `height`, `sizes` and `priority`. The loader returns relative URLs (files in `/public`) and URLs that are not Lynkow media unchanged. `remotePatterns` is not read when a custom loader is set.

## Blur placeholder

A 20px-wide JPEG makes a cheap placeholder. Inline it as a data URL on the server and pass it to `<Image>`:

```typescript
// lib/blur-data-url.ts
import { lynkow } from '@/lib/lynkow'

export async function getBlurDataUrl(imageUrl: string): Promise<string> {
  const tiny = lynkow.media.transform(imageUrl, { w: 20, quality: 50, format: 'jpeg' })
  const buffer = await (await fetch(tiny)).arrayBuffer()
  return `data:image/jpeg;base64,${Buffer.from(buffer).toString('base64')}`
}
```

```tsx
// In an async server component, for an article with a featured image
const src = article.featuredImage!
const blurDataURL = await getBlurDataUrl(src)

<Image src={src} alt={article.featuredImageAlt ?? ''} width={1200} height={630} placeholder="blur" blurDataURL={blurDataURL} />
```

## Open Graph image

Prefer the dedicated OG image, then the featured image. Both `og` variants are 1200x630:

```typescript
const ogImage = article.ogImageVariants?.og ?? article.featuredImageVariants?.og
```

Wiring it into `generateMetadata()` is covered in [SEO & Analytics](/sdk/media-seo/seo-analytics).

## Next Steps

- [SEO & Analytics](/sdk/media-seo/seo-analytics): meta tags and Open Graph
- [Structured Content](/sdk/features/structured-content): `image` fields in `customData`