Netlify Image CDN

Provider documentation

Netlify Image CDN

Resize local and remote images through Netlify Image CDN.

Setup

Install the framework package and the core package for the provider import:

npm install @desource/image @desource/image-svelte

Save this as image.config.ts beside your example component. Replace sample domains and identifiers with your own.

import type { ImageConfig } from '@desource/image';
import { netlifyImageCdnProvider } from '@desource/image/providers/netlifyImageCdn';

export const imageConfig = {
  provider: 'netlifyImageCdn',
  providers: {
    netlifyImageCdn: netlifyImageCdnProvider({
      "path": "/.netlify/images"
    })
  }
} satisfies ImageConfig;

Registering this provider makes it the default for the configured components. To mix services, register each provider and set provider="netlifyImageCdn" on the image that should use this one.

Image source

Use a deployment-relative path or an absolute remote source allowed by Netlify.

/img/hero.jpg

Usage

The example uses the shared configuration above and the Svelte image component.

<script lang="ts">
  import { Image, setImageConfig } from '@desource/image-svelte';
  import { imageConfig } from './image.config';

  setImageConfig(imageConfig);
</script>

<Image
  src="/img/hero.jpg"
  alt="Sample image" width={800} height={500}
  modifiers={{
  "format": "webp",
  "quality": 80,
  "fit": "cover"
}}
/>

Provider options

path
Endpoint path. Defaults to /.netlify/images; baseURL takes precedence.

Pass shared defaults such as screens, domains, aliases and presets to the image configuration. Pass provider-specific defaults as modifiers in the provider factory.

Modifiers

Supports width, height, quality, format, fit and position. Fit accepts cover, contain or fill; position accepts top, right, bottom, left or center. JPEG maps to jpg.

Set dimensions on the component and pass service-specific operations through modifiers, as shown above. See the provider source for exact mappings and the service documentation for accepted values.

Provider notes

  • Auto-detected on Netlify unless the Large Media environment is present.
  • Configure remote_images in netlify.toml for remote origins. Generating a URL does not create a local Netlify optimizer.

Allow a remote origin on Netlify

[images]
remote_images = ['https://images\.example\.com/.*']
← Back to all providers